summaryrefslogtreecommitdiff
path: root/lib/ansible/parsing/mod_args.py
diff options
context:
space:
mode:
Diffstat (limited to 'lib/ansible/parsing/mod_args.py')
-rw-r--r--lib/ansible/parsing/mod_args.py27
1 files changed, 23 insertions, 4 deletions
diff --git a/lib/ansible/parsing/mod_args.py b/lib/ansible/parsing/mod_args.py
index 3d158202ff..fbf5e1c3d6 100644
--- a/lib/ansible/parsing/mod_args.py
+++ b/lib/ansible/parsing/mod_args.py
@@ -21,7 +21,7 @@ __metaclass__ = type
from ansible.compat.six import iteritems, string_types
-from ansible.errors import AnsibleParserError
+from ansible.errors import AnsibleParserError,AnsibleError
from ansible.plugins import module_loader
from ansible.parsing.splitter import parse_kv, split_args
from ansible.template import Templar
@@ -137,7 +137,16 @@ class ModuleArgsParser:
# than those which may be parsed/normalized next
final_args = dict()
if additional_args:
- final_args.update(additional_args)
+ if isinstance(additional_args, string_types):
+ templar = Templar(loader=None)
+ if templar._contains_vars(additional_args):
+ final_args['_variable_params'] = additional_args
+ else:
+ raise AnsibleParserError("Complex args containing variables cannot use bare variables, and must use the full variable style ('{{var_name}}')")
+ elif isinstance(additional_args, dict):
+ final_args.update(additional_args)
+ else:
+ raise AnsibleParserError('Complex args must be a dictionary or variable string ("{{var}}").')
# how we normalize depends if we figured out what the module name is
# yet. If we have already figured it out, it's an 'old style' invocation.
@@ -155,6 +164,13 @@ class ModuleArgsParser:
tmp_args = parse_kv(tmp_args)
args.update(tmp_args)
+ # only internal variables can start with an underscore, so
+ # we don't allow users to set them directy in arguments
+ if args and action not in ('command', 'shell', 'script', 'raw'):
+ for arg in args:
+ if arg.startswith('_ansible_'):
+ raise AnsibleError("invalid parameter specified for action '%s': '%s'" % (action, arg))
+
# finally, update the args we're going to return with the ones
# which were normalized above
if args:
@@ -206,18 +222,21 @@ class ModuleArgsParser:
action = None
args = None
+ actions_allowing_raw = ('command', 'shell', 'script', 'raw')
if isinstance(thing, dict):
# form is like: copy: { src: 'a', dest: 'b' } ... common for structured (aka "complex") args
thing = thing.copy()
if 'module' in thing:
- action = thing['module']
+ action, module_args = self._split_module_string(thing['module'])
args = thing.copy()
+ check_raw = action in actions_allowing_raw
+ args.update(parse_kv(module_args, check_raw=check_raw))
del args['module']
elif isinstance(thing, string_types):
# form is like: copy: src=a dest=b ... common shorthand throughout ansible
(action, args) = self._split_module_string(thing)
- check_raw = action in ('command', 'shell', 'script', 'raw')
+ check_raw = action in actions_allowing_raw
args = parse_kv(args, check_raw=check_raw)
else: