Allow non-string types in with_items variables

This commit is contained in:
Daniel Hokka Zakrisson 2012-10-01 17:07:51 +02:00
parent 886a17853f
commit 695b4bcb46
2 changed files with 40 additions and 1 deletions

View file

@ -371,7 +371,7 @@ def varReplaceWithItems(basedir, varname, vars):
d[k] = varReplaceWithItems(basedir, v, vars)
return d
else:
raise Exception("invalid with_items type")
return varname
def template(basedir, text, vars):

View file

@ -249,6 +249,45 @@ class TestUtils(unittest.TestCase):
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