Skip to content

Commit

Permalink
[stable-2.9] Prevent ansible_failed_task from further templating (ans…
Browse files Browse the repository at this point in the history
…ible#74290)

* Prevent ansible_failed_task from further templating

Fixes ansible#74036

* Add changelog.
(cherry picked from commit 664531d)

Co-authored-by: Martin Krizek <martin.krizek@gmail.com>
  • Loading branch information
mkrizek authored and sivel committed Jul 8, 2021
1 parent 7a5c66f commit 970fb3b
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 2 deletions.
2 changes: 2 additions & 0 deletions changelogs/fragments/74036-unsafe-ansible_failed_task.yml
@@ -0,0 +1,2 @@
bugfixes:
- Prevent ``ansible_failed_task`` from further templating (https://github.com/ansible/ansible/issues/74036)
3 changes: 2 additions & 1 deletion lib/ansible/plugins/strategy/__init__.py
Expand Up @@ -49,6 +49,7 @@
from ansible.plugins import loader as plugin_loader
from ansible.template import Templar
from ansible.utils.display import Display
from ansible.utils.unsafe_proxy import wrap_var
from ansible.utils.vars import combine_vars
from ansible.vars.clean import strip_internal_keys, module_response_deepcopy

Expand Down Expand Up @@ -577,7 +578,7 @@ def search_handler_blocks_by_name(handler_name, handler_blocks):
self._variable_manager.set_nonpersistent_facts(
original_host.name,
dict(
ansible_failed_task=original_task.serialize(),
ansible_failed_task=wrap_var(original_task.serialize()),
ansible_failed_result=task_result._result,
),
)
Expand Down
7 changes: 6 additions & 1 deletion test/integration/targets/blocks/runme.sh
Expand Up @@ -94,4 +94,9 @@ cat rc_test.out
[ "$(grep -c 'failed=0' rc_test.out)" -eq 1 ]
rm -f rc_test.out

ansible-playbook finalized_task.yml "$@"
# test notify inheritance
ansible-playbook inherit_notify.yml "$@"

ansible-playbook unsafe_failed_task.yml "$@"

ansible-playbook finalized_task.yml "$@"
17 changes: 17 additions & 0 deletions test/integration/targets/blocks/unsafe_failed_task.yml
@@ -0,0 +1,17 @@
- hosts: localhost
gather_facts: false
vars:
- data: {}
tasks:
- block:
- name: template error
debug:
msg: "{{ data.value }}"
rescue:
- debug:
msg: "{{ ansible_failed_task.action }}"

- assert:
that:
- ansible_failed_task.name == "template error"
- ansible_failed_task.action == "debug"

0 comments on commit 970fb3b

Please sign in to comment.