diff --git a/changelogs/fragments/mod_args.yml b/changelogs/fragments/mod_args.yml new file mode 100644 index 00000000000..6f6026198e8 --- /dev/null +++ b/changelogs/fragments/mod_args.yml @@ -0,0 +1,3 @@ +--- +bugfixes: + - Reword warning if the reserved keyword _ansible_ used as a module parameter (https://github.com/ansible/ansible/issues/82514). diff --git a/lib/ansible/parsing/mod_args.py b/lib/ansible/parsing/mod_args.py index 2e024f0a446..56e7e98151e 100644 --- a/lib/ansible/parsing/mod_args.py +++ b/lib/ansible/parsing/mod_args.py @@ -179,7 +179,11 @@ class ModuleArgsParser: for arg in args: arg = to_text(arg) if arg.startswith('_ansible_'): - raise AnsibleError("invalid parameter specified for action '%s': '%s'" % (action, arg)) + err_msg = ( + f"Invalid parameter specified beginning with keyword '_ansible_' for action '{action !s}': '{arg !s}'. " + "The prefix '_ansible_' is reserved for internal use only." + ) + raise AnsibleError(err_msg) # finally, update the args we're going to return with the ones # which were normalized above diff --git a/test/integration/targets/set_fact/runme.sh b/test/integration/targets/set_fact/runme.sh index 93093599ec9..7fd548c3f11 100755 --- a/test/integration/targets/set_fact/runme.sh +++ b/test/integration/targets/set_fact/runme.sh @@ -34,3 +34,6 @@ ansible-playbook -i inventory set_fact_empty_str_key.yml # https://github.com/ansible/ansible/issues/21088 ansible-playbook -i inventory "$@" set_fact_auto_unsafe.yml + +ansible-playbook -i inventory "$@" set_fact_ansible_vars.yml 2>&1 | tee test_set_fact_ansible_vars.out +test "$(grep -E -c 'is reserved for internal use only.' test_set_fact_ansible_vars.out)" = 1 diff --git a/test/integration/targets/set_fact/set_fact_ansible_vars.yml b/test/integration/targets/set_fact/set_fact_ansible_vars.yml new file mode 100644 index 00000000000..53ed5357d75 --- /dev/null +++ b/test/integration/targets/set_fact/set_fact_ansible_vars.yml @@ -0,0 +1,9 @@ +- name: Test set_fact with key starting with reserved keyword '_ansible_' + hosts: testhost + gather_facts: no + tasks: + - name: Define fact with key starting with reserved keyword '_ansible_' + set_fact: + _ansible_foo: bar + ignore_errors: yes + register: r