Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix only_if statements referencing non-string types #1109

Merged
merged 1 commit into from
Sep 27, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 6 additions & 5 deletions lib/ansible/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,8 +269,9 @@ def varReplace(raw, vars, do_repr=False, depth=0):
# original)

try:
replacement = unicode(_varLookup(m.group(2), vars, depth))
replacement = varReplace(replacement, vars, depth=depth + 1)
replacement = _varLookup(m.group(2), vars, depth)
if isinstance(replacement, (str, unicode)):
replacement = varReplace(replacement, vars, depth=depth + 1)
except VarNotFoundException:
replacement = m.group()

Expand All @@ -282,9 +283,9 @@ def varReplace(raw, vars, do_repr=False, depth=0):
(raw[start - 1] == '"' and raw[end] == '"'))):
start -= 1
end += 1
done.append(raw[:start]) # Keep stuff leading up to token
done.append(replacement) # Append replacement value
raw = raw[end:] # Continue with remainder of string
done.append(raw[:start]) # Keep stuff leading up to token
done.append(unicode(replacement)) # Append replacement value
raw = raw[end:] # Continue with remainder of string

return ''.join(done)

Expand Down
10 changes: 10 additions & 0 deletions test/TestUtils.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,16 @@ def test_varReplace_repr_varpartindex(self):
res = ansible.utils.varReplace(template, vars, do_repr=True)
assert eval(res)

def test_varReplace_repr_nonstr(self):
vars = {
'foo': True,
'bar': 1L,
}

template = '${foo} == $bar'
res = ansible.utils.varReplace(template, vars, do_repr=True)
assert res == 'True == 1L'

def test_template_varReplace_iterated(self):
template = 'hello $who'
vars = {
Expand Down