Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure task from the worker is finalized/squashed #73881

Merged
merged 4 commits into from Mar 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions 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)
7 changes: 7 additions & 0 deletions lib/ansible/playbook/base.py
Expand Up @@ -545,6 +545,13 @@ def from_attrs(self, attrs):
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
Expand Down
17 changes: 17 additions & 0 deletions 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
3 changes: 3 additions & 0 deletions test/integration/targets/blocks/roles/fail/tasks/main.yml
@@ -0,0 +1,3 @@
- name: Fail
fail:
msg: fail