Rename varReplaceWithItems to template_ds
This commit is contained in:
parent
35d841f780
commit
383dc30560
4 changed files with 14 additions and 14 deletions
|
@ -111,7 +111,7 @@ class Play(object):
|
||||||
plugin_name = k[5:]
|
plugin_name = k[5:]
|
||||||
if plugin_name not in utils.plugins.lookup_loader:
|
if plugin_name not in utils.plugins.lookup_loader:
|
||||||
raise errors.AnsibleError("cannot find lookup plugin named %s for usage in with_%s" % (plugin_name, plugin_name))
|
raise errors.AnsibleError("cannot find lookup plugin named %s for usage in with_%s" % (plugin_name, plugin_name))
|
||||||
terms = utils.varReplaceWithItems(self.basedir, x[k], task_vars)
|
terms = utils.template_ds(self.basedir, x[k], task_vars)
|
||||||
items = utils.plugins.lookup_loader.get(plugin_name, basedir=self.basedir, runner=None).run(terms, inject=task_vars)
|
items = utils.plugins.lookup_loader.get(plugin_name, basedir=self.basedir, runner=None).run(terms, inject=task_vars)
|
||||||
|
|
||||||
for item in items:
|
for item in items:
|
||||||
|
@ -119,7 +119,7 @@ class Play(object):
|
||||||
mv['item'] = item
|
mv['item'] = item
|
||||||
for t in tokens[1:]:
|
for t in tokens[1:]:
|
||||||
(k,v) = t.split("=", 1)
|
(k,v) = t.split("=", 1)
|
||||||
mv[k] = utils.varReplaceWithItems(self.basedir, v, mv)
|
mv[k] = utils.template_ds(self.basedir, v, mv)
|
||||||
include_file = utils.template(self.basedir, tokens[0], mv)
|
include_file = utils.template(self.basedir, tokens[0], mv)
|
||||||
data = utils.parse_yaml_from_file(utils.path_dwim(self.basedir, include_file))
|
data = utils.parse_yaml_from_file(utils.path_dwim(self.basedir, include_file))
|
||||||
for y in data:
|
for y in data:
|
||||||
|
|
|
@ -273,7 +273,7 @@ class Runner(object):
|
||||||
items_plugin = self.module_vars.get('items_lookup_plugin', None)
|
items_plugin = self.module_vars.get('items_lookup_plugin', None)
|
||||||
if items_plugin is not None and items_plugin in utils.plugins.lookup_loader:
|
if items_plugin is not None and items_plugin in utils.plugins.lookup_loader:
|
||||||
items_terms = self.module_vars.get('items_lookup_terms', '')
|
items_terms = self.module_vars.get('items_lookup_terms', '')
|
||||||
items_terms = utils.varReplaceWithItems(self.basedir, items_terms, inject)
|
items_terms = utils.template_ds(self.basedir, items_terms, inject)
|
||||||
items = utils.plugins.lookup_loader.get(items_plugin, runner=self, basedir=self.basedir).run(items_terms, inject=inject)
|
items = utils.plugins.lookup_loader.get(items_plugin, runner=self, basedir=self.basedir).run(items_terms, inject=inject)
|
||||||
if type(items) != list:
|
if type(items) != list:
|
||||||
raise errors.AnsibleError("lookup plugins have to return a list: %r" % items)
|
raise errors.AnsibleError("lookup plugins have to return a list: %r" % items)
|
||||||
|
|
|
@ -177,8 +177,8 @@ def _varReplaceFilesAndPipes(basedir, raw, vars):
|
||||||
|
|
||||||
return ''.join(done)
|
return ''.join(done)
|
||||||
|
|
||||||
def varReplaceWithItems(basedir, varname, vars):
|
def template_ds(basedir, varname, vars):
|
||||||
''' helper function used by with_items '''
|
''' templates a data structure by traversing it and substituting for other data structures '''
|
||||||
|
|
||||||
if isinstance(varname, basestring):
|
if isinstance(varname, basestring):
|
||||||
m = _varFind(varname, vars)
|
m = _varFind(varname, vars)
|
||||||
|
@ -186,17 +186,17 @@ def varReplaceWithItems(basedir, varname, vars):
|
||||||
return varname
|
return varname
|
||||||
if m['start'] == 0 and m['end'] == len(varname):
|
if m['start'] == 0 and m['end'] == len(varname):
|
||||||
if m['replacement'] is not None:
|
if m['replacement'] is not None:
|
||||||
return varReplaceWithItems(basedir, m['replacement'], vars)
|
return template_ds(basedir, m['replacement'], vars)
|
||||||
else:
|
else:
|
||||||
return varname
|
return varname
|
||||||
else:
|
else:
|
||||||
return template(basedir, varname, vars)
|
return template(basedir, varname, vars)
|
||||||
elif isinstance(varname, (list, tuple)):
|
elif isinstance(varname, (list, tuple)):
|
||||||
return [varReplaceWithItems(basedir, v, vars) for v in varname]
|
return [template_ds(basedir, v, vars) for v in varname]
|
||||||
elif isinstance(varname, dict):
|
elif isinstance(varname, dict):
|
||||||
d = {}
|
d = {}
|
||||||
for (k, v) in varname.iteritems():
|
for (k, v) in varname.iteritems():
|
||||||
d[k] = varReplaceWithItems(basedir, v, vars)
|
d[k] = template_ds(basedir, v, vars)
|
||||||
return d
|
return d
|
||||||
else:
|
else:
|
||||||
return varname
|
return varname
|
||||||
|
|
|
@ -286,9 +286,9 @@ class TestUtils(unittest.TestCase):
|
||||||
assert res == u'hello world world'
|
assert res == u'hello world world'
|
||||||
|
|
||||||
#####################################
|
#####################################
|
||||||
### varReplaceWithItems function tests
|
### template_ds function tests
|
||||||
|
|
||||||
def test_varReplaceWithItems_basic(self):
|
def test_template_ds_basic(self):
|
||||||
vars = {
|
vars = {
|
||||||
'data': {
|
'data': {
|
||||||
'var': [
|
'var': [
|
||||||
|
@ -313,19 +313,19 @@ class TestUtils(unittest.TestCase):
|
||||||
}
|
}
|
||||||
|
|
||||||
template = '${data.var}'
|
template = '${data.var}'
|
||||||
res = ansible.utils.varReplaceWithItems(None, template, vars)
|
res = ansible.utils.template_ds(None, template, vars)
|
||||||
assert sorted(res) == sorted(vars['data']['var'])
|
assert sorted(res) == sorted(vars['data']['var'])
|
||||||
|
|
||||||
template = '${data.types}'
|
template = '${data.types}'
|
||||||
res = ansible.utils.varReplaceWithItems(None, template, vars)
|
res = ansible.utils.template_ds(None, template, vars)
|
||||||
assert sorted(res) == sorted(vars['data']['types'])
|
assert sorted(res) == sorted(vars['data']['types'])
|
||||||
|
|
||||||
template = '${data.alphas}'
|
template = '${data.alphas}'
|
||||||
res = ansible.utils.varReplaceWithItems(None, template, vars)
|
res = ansible.utils.template_ds(None, template, vars)
|
||||||
assert sorted(res) == sorted(vars['alphas'])
|
assert sorted(res) == sorted(vars['alphas'])
|
||||||
|
|
||||||
template = '${data.nonexisting}'
|
template = '${data.nonexisting}'
|
||||||
res = ansible.utils.varReplaceWithItems(None, template, vars)
|
res = ansible.utils.template_ds(None, template, vars)
|
||||||
assert res == template
|
assert res == template
|
||||||
|
|
||||||
#####################################
|
#####################################
|
||||||
|
|
Loading…
Reference in a new issue