From 885e3766a8d637c00254d25ea91e77733cc904b8 Mon Sep 17 00:00:00 2001 From: Brian Coca Date: Tue, 6 Aug 2024 16:18:41 -0400 Subject: [PATCH] core: raw params better error msg (#83726) * less confusing error msg * also remove 'removed' include --- changelogs/fragments/raw_clean_msg.yml | 2 ++ lib/ansible/constants.py | 8 ++++---- lib/ansible/parsing/mod_args.py | 15 +++++++-------- 3 files changed, 13 insertions(+), 12 deletions(-) create mode 100644 changelogs/fragments/raw_clean_msg.yml diff --git a/changelogs/fragments/raw_clean_msg.yml b/changelogs/fragments/raw_clean_msg.yml new file mode 100644 index 00000000000..ebae8dd4523 --- /dev/null +++ b/changelogs/fragments/raw_clean_msg.yml @@ -0,0 +1,2 @@ +bugfixes: + - the raw arguments error now just displays the short names of modules instead of every possible variation diff --git a/lib/ansible/constants.py b/lib/ansible/constants.py index 5e5799c1326..8ab684cbe38 100644 --- a/lib/ansible/constants.py +++ b/lib/ansible/constants.py @@ -176,10 +176,10 @@ INTERNAL_STATIC_VARS = frozenset( ] ) LOCALHOST = ('127.0.0.1', 'localhost', '::1') -MODULE_REQUIRE_ARGS = tuple(add_internal_fqcns(('command', 'win_command', 'ansible.windows.win_command', 'shell', 'win_shell', - 'ansible.windows.win_shell', 'raw', 'script'))) -MODULE_NO_JSON = tuple(add_internal_fqcns(('command', 'win_command', 'ansible.windows.win_command', 'shell', 'win_shell', - 'ansible.windows.win_shell', 'raw'))) +WIN_MOVED = ['ansible.windows.win_command', 'ansible.windows.win_shell'] +MODULE_REQUIRE_ARGS_SIMPLE = ['command', 'raw', 'script', 'shell', 'win_command', 'win_shell'] +MODULE_REQUIRE_ARGS = tuple(add_internal_fqcns(MODULE_REQUIRE_ARGS_SIMPLE) + WIN_MOVED) +MODULE_NO_JSON = tuple(add_internal_fqcns(('command', 'win_command', 'shell', 'win_shell', 'raw')) + WIN_MOVED) RESTRICTED_RESULT_KEYS = ('ansible_rsync_path', 'ansible_playbook_python', 'ansible_facts') SYNTHETIC_COLLECTIONS = ('ansible.builtin', 'ansible.legacy') TREE_DIR = None diff --git a/lib/ansible/parsing/mod_args.py b/lib/ansible/parsing/mod_args.py index fb982f54426..eeca065a852 100644 --- a/lib/ansible/parsing/mod_args.py +++ b/lib/ansible/parsing/mod_args.py @@ -28,11 +28,9 @@ from ansible.utils.fqcn import add_internal_fqcns from ansible.utils.sentinel import Sentinel -# For filtering out modules correctly below -FREEFORM_ACTIONS = frozenset(C.MODULE_REQUIRE_ARGS) - -RAW_PARAM_MODULES = FREEFORM_ACTIONS.union(add_internal_fqcns(( - 'include', +# modules formated for user msg +FREEFORM_ACTIONS = set(C.MODULE_REQUIRE_ARGS_SIMPLE) +RAW_PARAM_MODULES = FREEFORM_ACTIONS.union(set([ 'include_vars', 'include_tasks', 'include_role', @@ -42,8 +40,9 @@ RAW_PARAM_MODULES = FREEFORM_ACTIONS.union(add_internal_fqcns(( 'group_by', 'set_fact', 'meta', -))) - +])) +# For filtering out modules correctly below, use all permutations +RAW_PARAM_MODULES_MATCH = add_internal_fqcns(RAW_PARAM_MODULES) + C.WIN_MOVED BUILTIN_TASKS = frozenset(add_internal_fqcns(( 'meta', 'include_tasks', @@ -352,7 +351,7 @@ 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: + elif args.get('_raw_params', '') != '' and action not in RAW_PARAM_MODULES_MATCH: templar = Templar(loader=None) raw_params = args.pop('_raw_params') if templar.is_template(raw_params):