From c9086061ca192e058f991d647ad5e7344dc0747b Mon Sep 17 00:00:00 2001 From: Jordan Borean Date: Thu, 21 Mar 2024 01:34:57 +1000 Subject: [PATCH] Allow check mode async task disabling check_mode (#82827) * Allow check mode async task disabling check_mode Allows running an async task with check_mode: False when the playbook is being run in check mode. * Add check_mode attribute to internal cleanup task --- changelogs/fragments/async-task-check-mode.yml | 4 ++++ lib/ansible/executor/task_executor.py | 8 +++++++- test/integration/targets/async/check_task_test.yml | 8 ++++++++ test/integration/targets/async/tasks/main.yml | 12 ++++++++++++ 4 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 changelogs/fragments/async-task-check-mode.yml create mode 100644 test/integration/targets/async/check_task_test.yml diff --git a/changelogs/fragments/async-task-check-mode.yml b/changelogs/fragments/async-task-check-mode.yml new file mode 100644 index 00000000000..24af245f501 --- /dev/null +++ b/changelogs/fragments/async-task-check-mode.yml @@ -0,0 +1,4 @@ +bugfixes: +- >- + async - Fix bug that stopped running async task in ``--check`` when ``check_mode: False`` was set as a task attribute + - https://github.com/ansible/ansible/issues/82811 diff --git a/lib/ansible/executor/task_executor.py b/lib/ansible/executor/task_executor.py index 5b3e5326b6e..2d615e29d90 100644 --- a/lib/ansible/executor/task_executor.py +++ b/lib/ansible/executor/task_executor.py @@ -840,7 +840,12 @@ class TaskExecutor: # that (with a sleep for "poll" seconds between each retry) until the # async time limit is exceeded. - async_task = Task.load(dict(action='async_status', args={'jid': async_jid}, environment=self._task.environment)) + async_task = Task.load(dict( + action='async_status', + args={'jid': async_jid}, + check_mode=self._task.check_mode, + environment=self._task.environment, + )) # FIXME: this is no longer the case, normal takes care of all, see if this can just be generalized # Because this is an async task, the action handler is async. However, @@ -912,6 +917,7 @@ class TaskExecutor: 'jid': async_jid, 'mode': 'cleanup', }, + 'check_mode': self._task.check_mode, 'environment': self._task.environment, } ) diff --git a/test/integration/targets/async/check_task_test.yml b/test/integration/targets/async/check_task_test.yml new file mode 100644 index 00000000000..f8756408a1b --- /dev/null +++ b/test/integration/targets/async/check_task_test.yml @@ -0,0 +1,8 @@ +- hosts: localhost + gather_facts: false + tasks: + - name: Async in check mode task disabled test + command: sleep 5 + async: 6 + poll: 1 + check_mode: False diff --git a/test/integration/targets/async/tasks/main.yml b/test/integration/targets/async/tasks/main.yml index f5e5c992e7e..491be966a04 100644 --- a/test/integration/targets/async/tasks/main.yml +++ b/test/integration/targets/async/tasks/main.yml @@ -298,3 +298,15 @@ - assert: that: - '"ASYNC POLL on localhost" in callback_output.stdout' + +- name: run playbook in --check with task disabling check mode + command: ansible-playbook {{ role_path }}/check_task_test.yml --check + register: check_task_disabled_output + delegate_to: localhost + environment: + ANSIBLE_NOCOLOR: 'true' + ANSIBLE_FORCE_COLOR: 'false' + +- assert: + that: + - '"ASYNC OK on localhost" in check_task_disabled_output.stdout'