Only expand lists in templating inside of module action lines, to avoid breaking usage with with_items and "in" statements, etc
This commit is contained in:
parent
acf2c23808
commit
0837a29e51
3 changed files with 7 additions and 7 deletions
|
@ -404,7 +404,7 @@ class Runner(object):
|
||||||
return ReturnData(host=host, comm_ok=False, result=result)
|
return ReturnData(host=host, comm_ok=False, result=result)
|
||||||
|
|
||||||
module_name = utils.template(self.basedir, module_name, inject)
|
module_name = utils.template(self.basedir, module_name, inject)
|
||||||
module_args = utils.template(self.basedir, module_args, inject)
|
module_args = utils.template(self.basedir, module_args, inject, expand_lists=True)
|
||||||
|
|
||||||
tmp = ''
|
tmp = ''
|
||||||
if self.module_name != 'raw':
|
if self.module_name != 'raw':
|
||||||
|
|
|
@ -280,7 +280,7 @@ def _varFind(text):
|
||||||
path.append(text[part_start[0]:var_end])
|
path.append(text[part_start[0]:var_end])
|
||||||
return {'path': path, 'start': start, 'end': end}
|
return {'path': path, 'start': start, 'end': end}
|
||||||
|
|
||||||
def varReplace(raw, vars, depth=0):
|
def varReplace(raw, vars, depth=0, expand_lists=False):
|
||||||
''' Perform variable replacement of $variables in string raw using vars dictionary '''
|
''' Perform variable replacement of $variables in string raw using vars dictionary '''
|
||||||
# this code originally from yum
|
# this code originally from yum
|
||||||
|
|
||||||
|
@ -300,10 +300,10 @@ def varReplace(raw, vars, depth=0):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
replacement = _varLookup(m['path'], vars, depth)
|
replacement = _varLookup(m['path'], vars, depth)
|
||||||
if isinstance(replacement, (list, tuple)):
|
if expand_lists and isinstance(replacement, (list, tuple)):
|
||||||
replacement = ",".join(replacement)
|
replacement = ",".join(replacement)
|
||||||
if isinstance(replacement, (str, unicode)):
|
if isinstance(replacement, (str, unicode)):
|
||||||
replacement = varReplace(replacement, vars, depth=depth + 1)
|
replacement = varReplace(replacement, vars, depth=depth+1, expand_lists=expand_lists)
|
||||||
except VarNotFoundException:
|
except VarNotFoundException:
|
||||||
replacement = raw[m['start']:m['end']]
|
replacement = raw[m['start']:m['end']]
|
||||||
|
|
||||||
|
@ -376,7 +376,7 @@ def varReplaceWithItems(basedir, varname, vars):
|
||||||
return varname
|
return varname
|
||||||
|
|
||||||
|
|
||||||
def template(basedir, text, vars):
|
def template(basedir, text, vars, expand_lists=False):
|
||||||
''' run a text buffer through the templating engine until it no longer changes '''
|
''' run a text buffer through the templating engine until it no longer changes '''
|
||||||
|
|
||||||
prev_text = ''
|
prev_text = ''
|
||||||
|
@ -384,7 +384,7 @@ def template(basedir, text, vars):
|
||||||
text = text.decode('utf-8')
|
text = text.decode('utf-8')
|
||||||
except UnicodeEncodeError:
|
except UnicodeEncodeError:
|
||||||
pass # already unicode
|
pass # already unicode
|
||||||
text = varReplace(unicode(text), vars)
|
text = varReplace(unicode(text), vars, expand_lists=expand_lists)
|
||||||
text = varReplaceFilesAndPipes(basedir, text)
|
text = varReplaceFilesAndPipes(basedir, text)
|
||||||
return text
|
return text
|
||||||
|
|
||||||
|
|
|
@ -221,7 +221,7 @@ class TestUtils(unittest.TestCase):
|
||||||
}
|
}
|
||||||
|
|
||||||
template = 'yum pkg=${list} state=installed'
|
template = 'yum pkg=${list} state=installed'
|
||||||
res = ansible.utils.varReplace(template, vars)
|
res = ansible.utils.varReplace(template, vars, expand_lists=True)
|
||||||
assert res == 'yum pkg=foo,bar,baz state=installed'
|
assert res == 'yum pkg=foo,bar,baz state=installed'
|
||||||
|
|
||||||
def test_template_varReplace_iterated(self):
|
def test_template_varReplace_iterated(self):
|
||||||
|
|
Loading…
Reference in a new issue