diff --git a/lib/ansible/utils.py b/lib/ansible/utils.py index 30390cc90f..3cbf0d42f2 100644 --- a/lib/ansible/utils.py +++ b/lib/ansible/utils.py @@ -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): diff --git a/test/TestUtils.py b/test/TestUtils.py index da9faa11f3..fe2a086d89 100644 --- a/test/TestUtils.py +++ b/test/TestUtils.py @@ -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