From 2c54fb1339dbf2564305b88893d29c57984604d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yannig=20Perr=C3=A9?= Date: Thu, 26 Nov 2015 18:24:12 +0200 Subject: [PATCH 1/2] Switch parameters validation after parsing in order to be more consistent between old and new style. --- lib/ansible/parsing/mod_args.py | 9 ++++++++- lib/ansible/parsing/splitter.py | 5 ----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/ansible/parsing/mod_args.py b/lib/ansible/parsing/mod_args.py index 3d158202ff..7e4f6132fa 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 @@ -155,6 +155,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 action not in ('command', 'shell', 'script', 'raw'): + for arg in args: + if arg.startswith('_') and arg not in ('_raw_params'): + 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: diff --git a/lib/ansible/parsing/splitter.py b/lib/ansible/parsing/splitter.py index 3bbf6e7e9c..c506603acb 100644 --- a/lib/ansible/parsing/splitter.py +++ b/lib/ansible/parsing/splitter.py @@ -83,11 +83,6 @@ def parse_kv(args, check_raw=False): k = x[:pos] v = x[pos + 1:] - # only internal variables can start with an underscore, so - # we don't allow users to set them directy in arguments - if k.startswith('_'): - raise AnsibleError("invalid parameter specified: '%s'" % k) - # FIXME: make the retrieval of this list of shell/command # options a function, so the list is centralized if check_raw and k not in ('creates', 'removes', 'chdir', 'executable', 'warn'): From 2fc7c8b4602ee7eb1db3250155ab7861387d7105 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yannig=20Perr=C3=A9?= Date: Sat, 28 Nov 2015 10:30:42 +0100 Subject: [PATCH 2/2] More restrictive test against variable name to allow setting variable starting with _. --- lib/ansible/parsing/mod_args.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ansible/parsing/mod_args.py b/lib/ansible/parsing/mod_args.py index 7e4f6132fa..ba2a37cea0 100644 --- a/lib/ansible/parsing/mod_args.py +++ b/lib/ansible/parsing/mod_args.py @@ -159,7 +159,7 @@ class ModuleArgsParser: # we don't allow users to set them directy in arguments if action not in ('command', 'shell', 'script', 'raw'): for arg in args: - if arg.startswith('_') and arg not in ('_raw_params'): + 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