summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--changelogs/fragments/57399-finalize-task-in-strategy.yml5
-rw-r--r--lib/ansible/playbook/base.py7
-rw-r--r--test/integration/targets/blocks/finalized_task.yml17
-rw-r--r--test/integration/targets/blocks/roles/fail/tasks/main.yml3
4 files changed, 32 insertions, 0 deletions
diff --git a/changelogs/fragments/57399-finalize-task-in-strategy.yml b/changelogs/fragments/57399-finalize-task-in-strategy.yml
new file mode 100644
index 0000000000..2a0e096a8c
--- /dev/null
+++ b/changelogs/fragments/57399-finalize-task-in-strategy.yml
@@ -0,0 +1,5 @@
+bugfixes:
+- Strategy - When building the task in the Strategy from the Worker,
+ ensure it is properly marked as finalized and squashed. Addresses an
+ issue with ``ansible_failed_task``.
+ (https://github.com/ansible/ansible/issues/57399)
diff --git a/lib/ansible/playbook/base.py b/lib/ansible/playbook/base.py
index df04592831..5fc050895f 100644
--- a/lib/ansible/playbook/base.py
+++ b/lib/ansible/playbook/base.py
@@ -545,6 +545,13 @@ class FieldAttributeBase(with_metaclass(BaseMeta, object)):
else:
setattr(self, attr, value)
+ # from_attrs is only used to create a finalized task
+ # from attrs from the Worker/TaskExecutor
+ # Those attrs are finalized and squashed in the TE
+ # and controller side use needs to reflect that
+ self._finalized = True
+ self._squashed = True
+
def serialize(self):
'''
Serializes the object derived from the base object into
diff --git a/test/integration/targets/blocks/finalized_task.yml b/test/integration/targets/blocks/finalized_task.yml
new file mode 100644
index 0000000000..300401b51c
--- /dev/null
+++ b/test/integration/targets/blocks/finalized_task.yml
@@ -0,0 +1,17 @@
+- hosts: localhost
+ gather_facts: false
+ tasks:
+ - block:
+ - include_role:
+ name: '{{ item }}'
+ loop:
+ - fail
+ rescue:
+ - debug:
+ msg: "{{ ansible_failed_task.name }}"
+
+ - assert:
+ that:
+ - ansible_failed_task.name == "Fail"
+ - ansible_failed_task.action == "fail"
+ - ansible_failed_task.parent is not defined
diff --git a/test/integration/targets/blocks/roles/fail/tasks/main.yml b/test/integration/targets/blocks/roles/fail/tasks/main.yml
new file mode 100644
index 0000000000..176fe5423d
--- /dev/null
+++ b/test/integration/targets/blocks/roles/fail/tasks/main.yml
@@ -0,0 +1,3 @@
+- name: Fail
+ fail:
+ msg: fail