Merge pull request #1109 from dhozac/fix-varReplace-repr
Fix only_if statements referencing non-string types
This commit is contained in:
commit
6506e17eff
2 changed files with 16 additions and 5 deletions
|
@ -269,8 +269,9 @@ def varReplace(raw, vars, do_repr=False, depth=0):
|
||||||
# original)
|
# original)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
replacement = unicode(_varLookup(m.group(2), vars, depth))
|
replacement = _varLookup(m.group(2), vars, depth)
|
||||||
replacement = varReplace(replacement, vars, depth=depth + 1)
|
if isinstance(replacement, (str, unicode)):
|
||||||
|
replacement = varReplace(replacement, vars, depth=depth + 1)
|
||||||
except VarNotFoundException:
|
except VarNotFoundException:
|
||||||
replacement = m.group()
|
replacement = m.group()
|
||||||
|
|
||||||
|
@ -282,9 +283,9 @@ def varReplace(raw, vars, do_repr=False, depth=0):
|
||||||
(raw[start - 1] == '"' and raw[end] == '"'))):
|
(raw[start - 1] == '"' and raw[end] == '"'))):
|
||||||
start -= 1
|
start -= 1
|
||||||
end += 1
|
end += 1
|
||||||
done.append(raw[:start]) # Keep stuff leading up to token
|
done.append(raw[:start]) # Keep stuff leading up to token
|
||||||
done.append(replacement) # Append replacement value
|
done.append(unicode(replacement)) # Append replacement value
|
||||||
raw = raw[end:] # Continue with remainder of string
|
raw = raw[end:] # Continue with remainder of string
|
||||||
|
|
||||||
return ''.join(done)
|
return ''.join(done)
|
||||||
|
|
||||||
|
|
|
@ -251,6 +251,16 @@ class TestUtils(unittest.TestCase):
|
||||||
res = ansible.utils.varReplace(template, vars, do_repr=True)
|
res = ansible.utils.varReplace(template, vars, do_repr=True)
|
||||||
assert eval(res)
|
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):
|
def test_template_varReplace_iterated(self):
|
||||||
template = 'hello $who'
|
template = 'hello $who'
|
||||||
vars = {
|
vars = {
|
||||||
|
|
Loading…
Reference in a new issue