Allow non-string types in with_items variables
This commit is contained in:
parent
886a17853f
commit
695b4bcb46
2 changed files with 40 additions and 1 deletions
|
@ -371,7 +371,7 @@ def varReplaceWithItems(basedir, varname, vars):
|
||||||
d[k] = varReplaceWithItems(basedir, v, vars)
|
d[k] = varReplaceWithItems(basedir, v, vars)
|
||||||
return d
|
return d
|
||||||
else:
|
else:
|
||||||
raise Exception("invalid with_items type")
|
return varname
|
||||||
|
|
||||||
|
|
||||||
def template(basedir, text, vars):
|
def template(basedir, text, vars):
|
||||||
|
|
|
@ -249,6 +249,45 @@ class TestUtils(unittest.TestCase):
|
||||||
|
|
||||||
assert res == u'hello world'
|
assert res == u'hello world'
|
||||||
|
|
||||||
|
#####################################
|
||||||
|
### varReplaceWithItems function tests
|
||||||
|
|
||||||
|
def test_varReplaceWithItems_basic(self):
|
||||||
|
vars = {
|
||||||
|
'data': {
|
||||||
|
'var': [
|
||||||
|
'foo',
|
||||||
|
'bar',
|
||||||
|
'baz',
|
||||||
|
],
|
||||||
|
'types': [
|
||||||
|
'str',
|
||||||
|
u'unicode',
|
||||||
|
1,
|
||||||
|
1L,
|
||||||
|
1.2,
|
||||||
|
],
|
||||||
|
'alphas': '$alphas',
|
||||||
|
},
|
||||||
|
'alphas': [
|
||||||
|
'abc',
|
||||||
|
'def',
|
||||||
|
'ghi',
|
||||||
|
],
|
||||||
|
}
|
||||||
|
|
||||||
|
template = '${data.var}'
|
||||||
|
res = ansible.utils.varReplaceWithItems(None, template, vars)
|
||||||
|
assert sorted(res) == sorted(vars['data']['var'])
|
||||||
|
|
||||||
|
template = '${data.types}'
|
||||||
|
res = ansible.utils.varReplaceWithItems(None, template, vars)
|
||||||
|
assert sorted(res) == sorted(vars['data']['types'])
|
||||||
|
|
||||||
|
template = '${data.alphas}'
|
||||||
|
res = ansible.utils.varReplaceWithItems(None, template, vars)
|
||||||
|
assert sorted(res) == sorted(vars['alphas'])
|
||||||
|
|
||||||
#####################################
|
#####################################
|
||||||
### Template function tests
|
### Template function tests
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue