Commit e12f9179 by Michael DeHaan

Allow args: var to be used to pass a variable in bare, and also templated…

Allow args: var to be used to pass a variable in bare, and also templated versions should also DWIM.
parent 6c778acd
...@@ -382,10 +382,18 @@ class Runner(object): ...@@ -382,10 +382,18 @@ class Runner(object):
inject['item'] = ",".join(items) inject['item'] = ",".join(items)
items = None items = None
# logic to decide how to run things depends on whether with_items is used # logic to replace complex args if possible
complex_args = self.complex_args
if isinstance(complex_args, basestring):
if complex_args in inject:
complex_args = inject[complex_args]
else:
complex_args = template.template(self.basedir, complex_args, inject)
complex_args = utils.safe_eval(complex_args)
# logic to decide how to run things depends on whether with_items is used
if items is None: if items is None:
return self._executor_internal_inner(host, self.module_name, self.module_args, inject, port, complex_args=self.complex_args) return self._executor_internal_inner(host, self.module_name, self.module_args, inject, port, complex_args=complex_args)
elif len(items) > 0: elif len(items) > 0:
# executing using with_items, so make multiple calls # executing using with_items, so make multiple calls
...@@ -404,7 +412,7 @@ class Runner(object): ...@@ -404,7 +412,7 @@ class Runner(object):
self.module_args, self.module_args,
inject, inject,
port, port,
complex_args=self.complex_args complex_args=complex_args
) )
results.append(result.result) results.append(result.result)
if result.comm_ok == False: if result.comm_ok == False:
......
...@@ -703,6 +703,9 @@ def safe_eval(str): ...@@ -703,6 +703,9 @@ def safe_eval(str):
return var.startswith("$") or '{{' in var return var.startswith("$") or '{{' in var
# do not allow method calls to modules # do not allow method calls to modules
if not isinstance(str, basestring):
# already templated to a datastructure, perhaps?
return str
if re.search(r'\w\.\w+\(', str): if re.search(r'\w\.\w+\(', str):
return str return str
# do not allow imports # do not allow imports
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment