From d5fd83265d3a050b02cdb9293708ae4deed8cbde Mon Sep 17 00:00:00 2001 From: Matt Davis <6775756+nitzmahone@users.noreply.github.com> Date: Wed, 15 Feb 2023 11:34:54 -0800 Subject: [PATCH] [2.13] don't ignore templated _raw_params that k=v parser failed to parse (#79913) (#79965) * don't ignore templated _raw_params that k=v parser failed to parse (#79913) fixes #79862 * backport test changes --- changelogs/fragments/79862-fix-varargs.yml | 2 ++ lib/ansible/executor/task_executor.py | 4 ++++ test/integration/targets/tasks/playbook.yml | 19 +++++++++++++++++++ test/integration/targets/tasks/runme.sh | 4 ++++ test/integration/targets/tasks/tasks/main.yml | 4 ---- 5 files changed, 29 insertions(+), 4 deletions(-) create mode 100644 changelogs/fragments/79862-fix-varargs.yml create mode 100644 test/integration/targets/tasks/playbook.yml create mode 100755 test/integration/targets/tasks/runme.sh delete mode 100644 test/integration/targets/tasks/tasks/main.yml diff --git a/changelogs/fragments/79862-fix-varargs.yml b/changelogs/fragments/79862-fix-varargs.yml new file mode 100644 index 00000000000..c455d7e563c --- /dev/null +++ b/changelogs/fragments/79862-fix-varargs.yml @@ -0,0 +1,2 @@ +bugfixes: +- TaskExecutor - don't ignore templated _raw_params that k=v parser failed to parse (https://github.com/ansible/ansible/issues/79862) diff --git a/lib/ansible/executor/task_executor.py b/lib/ansible/executor/task_executor.py index baeb1d1bea3..4fad7e7ce2f 100644 --- a/lib/ansible/executor/task_executor.py +++ b/lib/ansible/executor/task_executor.py @@ -534,6 +534,10 @@ class TaskExecutor: "(see https://docs.ansible.com/ansible/devel/reference_appendices/faq.html#argsplat-unsafe)") variable_params.update(self._task.args) self._task.args = variable_params + else: + # if we didn't get a dict, it means there's garbage remaining after k=v parsing, just give up + # see https://github.com/ansible/ansible/issues/79862 + raise AnsibleError(f"invalid or malformed argument: '{variable_params}'") # update no_log to task value, now that we have it templated no_log = self._task.no_log diff --git a/test/integration/targets/tasks/playbook.yml b/test/integration/targets/tasks/playbook.yml new file mode 100644 index 00000000000..80d9f8b1e89 --- /dev/null +++ b/test/integration/targets/tasks/playbook.yml @@ -0,0 +1,19 @@ +- hosts: localhost + gather_facts: false + tasks: + # make sure tasks with an undefined variable in the name are gracefully handled + - name: "Task name with undefined variable: {{ not_defined }}" + debug: + msg: Hello + + - name: ensure malformed raw_params on arbitrary actions are not ignored + debug: + garbage {{"with a template"}} + ignore_errors: true + register: bad_templated_raw_param + + - assert: + that: + - bad_templated_raw_param is failed + - | + "invalid or malformed argument: 'garbage with a template'" in bad_templated_raw_param.msg diff --git a/test/integration/targets/tasks/runme.sh b/test/integration/targets/tasks/runme.sh new file mode 100755 index 00000000000..2d78eafc07a --- /dev/null +++ b/test/integration/targets/tasks/runme.sh @@ -0,0 +1,4 @@ +#!/usr/bin/env bash + +ansible-playbook playbook.yml "$@" + diff --git a/test/integration/targets/tasks/tasks/main.yml b/test/integration/targets/tasks/tasks/main.yml deleted file mode 100644 index f6ac1114d0f..00000000000 --- a/test/integration/targets/tasks/tasks/main.yml +++ /dev/null @@ -1,4 +0,0 @@ -# make sure tasks with an undefined variable in the name are gracefully handled -- name: "Task name with undefined variable: {{ not_defined }}" - debug: - msg: Hello