Fix up raw_params for ansible.windows modules (#83830)

* Fix up raw_params for ansible.windows modules

Fixes up the logic for detecting if using ansible.windows.win_command or
ansible.windows.win_shell with _raw_params. These two modules are
special in that they can be referenced in 4 different ways but the
ansible.windows collection specific prefix needs to be manually added to
the list.

* Fix up sanity issue
pull/83834/head
Jordan Borean 3 months ago committed by GitHub
parent 718ce13673
commit 69fb629355
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -29,9 +29,7 @@ from ansible.utils.sentinel import Sentinel
# modules formated for user msg
FREEFORM_ACTIONS_SIMPLE = set(C.MODULE_REQUIRE_ARGS_SIMPLE)
FREEFORM_ACTIONS = frozenset(add_internal_fqcns(FREEFORM_ACTIONS_SIMPLE))
RAW_PARAM_MODULES = FREEFORM_ACTIONS_SIMPLE.union(set([
_BUILTIN_RAW_PARAM_MODULES_SIMPLE = set([
'include_vars',
'include_tasks',
'include_role',
@ -41,9 +39,12 @@ RAW_PARAM_MODULES = FREEFORM_ACTIONS_SIMPLE.union(set([
'group_by',
'set_fact',
'meta',
]))
])
FREEFORM_ACTIONS_SIMPLE = set(C.MODULE_REQUIRE_ARGS_SIMPLE)
FREEFORM_ACTIONS = frozenset(C.MODULE_REQUIRE_ARGS)
RAW_PARAM_MODULES_SIMPLE = _BUILTIN_RAW_PARAM_MODULES_SIMPLE.union(FREEFORM_ACTIONS_SIMPLE)
# For filtering out modules correctly below, use all permutations
RAW_PARAM_MODULES_MATCH = add_internal_fqcns(RAW_PARAM_MODULES) + C.WIN_MOVED
RAW_PARAM_MODULES = frozenset(add_internal_fqcns(RAW_PARAM_MODULES_SIMPLE)).union(FREEFORM_ACTIONS)
BUILTIN_TASKS = frozenset(add_internal_fqcns((
'meta',
'include_tasks',
@ -352,14 +353,14 @@ class ModuleArgsParser:
else:
raise AnsibleParserError("no module/action detected in task.",
obj=self._task_ds)
elif args.get('_raw_params', '') != '' and action not in RAW_PARAM_MODULES_MATCH:
elif args.get('_raw_params', '') != '' and action not in RAW_PARAM_MODULES:
templar = Templar(loader=None)
raw_params = args.pop('_raw_params')
if templar.is_template(raw_params):
args['_variable_params'] = raw_params
else:
raise AnsibleParserError("this task '%s' has extra params, which is only allowed in the following modules: %s" % (action,
", ".join(RAW_PARAM_MODULES)),
obj=self._task_ds)
raise AnsibleParserError(
"this task '%s' has extra params, which is only allowed in the following modules: %s" % (action, ", ".join(RAW_PARAM_MODULES_SIMPLE)),
obj=self._task_ds)
return (action, args, delegate_to)

@ -65,3 +65,23 @@
- win_ping_crash_result is not changed
- 'win_ping_crash_result.msg == "Unhandled exception while executing module: boom"'
- '"throw \"boom\"" in win_ping_crash_result.exception'
- name: verify that shortname _raw_params works
win_shell: echo "name=foo"
register: win_shell_short_res
failed_when: win_shell_short_res.stdout | trim != 'name=foo'
- name: verify that legacy _raw_params works
ansible.legacy.win_shell: echo "name=foo"
register: win_shell_legacy_res
failed_when: win_shell_legacy_res.stdout | trim != 'name=foo'
- name: verify that builtin _raw_params works
ansible.builtin.win_shell: echo "name=foo"
register: win_shell_builtin_res
failed_when: win_shell_builtin_res.stdout | trim != 'name=foo'
- name: verify that collection _raw_params works
ansible.windows.win_shell: echo "name=foo"
register: win_shell_collection_res
failed_when: win_shell_collection_res.stdout | trim != 'name=foo'

Loading…
Cancel
Save