From dfee6e19cad77c8f19fa0dcc558b1d1254963126 Mon Sep 17 00:00:00 2001 From: Daniel Hokka Zakrisson Date: Sun, 30 Sep 2012 11:41:44 +0200 Subject: [PATCH] Replace lists with a comma-separated join --- lib/ansible/utils.py | 2 ++ test/TestUtils.py | 13 +++++++++++++ 2 files changed, 15 insertions(+) diff --git a/lib/ansible/utils.py b/lib/ansible/utils.py index f07075746a4..bf700daa285 100644 --- a/lib/ansible/utils.py +++ b/lib/ansible/utils.py @@ -309,6 +309,8 @@ def varReplace(raw, vars, depth=0): try: replacement = _varLookup(m['path'], vars, depth) + if isinstance(replacement, (list, tuple)): + replacement = ",".join(replacement) if isinstance(replacement, (str, unicode)): replacement = varReplace(replacement, vars, depth=depth + 1) except VarNotFoundException: diff --git a/test/TestUtils.py b/test/TestUtils.py index 8ce5dacb0c7..ae9baa0432e 100644 --- a/test/TestUtils.py +++ b/test/TestUtils.py @@ -225,6 +225,19 @@ class TestUtils(unittest.TestCase): res = ansible.utils.varReplace(template, vars) assert res == 'bar' + def test_varReplace_list_join(self): + vars = { + 'list': [ + 'foo', + 'bar', + 'baz', + ], + } + + template = 'yum pkg=${list} state=installed' + res = ansible.utils.varReplace(template, vars) + assert res == 'yum pkg=foo,bar,baz state=installed' + def test_template_varReplace_iterated(self): template = 'hello $who' vars = {