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

Prevent ansible_failed_task from further templating #74290

Merged
merged 2 commits into from
Apr 15, 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
2 changes: 2 additions & 0 deletions changelogs/fragments/74036-unsafe-ansible_failed_task.yml
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,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 @@ -572,7 +573,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
2 changes: 2 additions & 0 deletions test/integration/targets/blocks/runme.sh
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,5 @@ rm -f role_complete_test.out

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

ansible-playbook unsafe_failed_task.yml "$@"
17 changes: 17 additions & 0 deletions test/integration/targets/blocks/unsafe_failed_task.yml
Original file line number Diff line number Diff line change
@@ -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"