diff --git a/changelogs/fragments/64789-regression-rescue-vars-not-defined.yml b/changelogs/fragments/64789-regression-rescue-vars-not-defined.yml new file mode 100644 index 00000000000..2ae04ae74b4 --- /dev/null +++ b/changelogs/fragments/64789-regression-rescue-vars-not-defined.yml @@ -0,0 +1,2 @@ +bugfixes: + - Fix regression when ``ansible_failed_task`` and ``ansible_failed_result`` are not defined in the rescue block (https://github.com/ansible/ansible/issues/64789) diff --git a/lib/ansible/plugins/strategy/__init__.py b/lib/ansible/plugins/strategy/__init__.py index 5f6974cea09..2275e5590d1 100644 --- a/lib/ansible/plugins/strategy/__init__.py +++ b/lib/ansible/plugins/strategy/__init__.py @@ -510,7 +510,7 @@ class StrategyBase: if state and iterator.get_active_state(state).run_state == iterator.ITERATING_RESCUE: self._tqm._stats.increment('rescued', original_host.name) self._variable_manager.set_nonpersistent_facts( - original_host, + original_host.name, dict( ansible_failed_task=original_task.serialize(), ansible_failed_result=task_result._result, diff --git a/test/integration/targets/blocks/block_rescue_vars.yml b/test/integration/targets/blocks/block_rescue_vars.yml new file mode 100644 index 00000000000..404f7a37923 --- /dev/null +++ b/test/integration/targets/blocks/block_rescue_vars.yml @@ -0,0 +1,16 @@ +- hosts: localhost + gather_facts: no + tasks: + - block: + - name: EXPECTED FAILURE + fail: + rescue: + - name: Assert that ansible_failed_task is defined + assert: + that: + - ansible_failed_task is defined + + - name: Assert that ansible_failed_result is defined + assert: + that: + - ansible_failed_result is defined diff --git a/test/integration/targets/blocks/runme.sh b/test/integration/targets/blocks/runme.sh index 3384bb9d9bb..f158735611f 100755 --- a/test/integration/targets/blocks/runme.sh +++ b/test/integration/targets/blocks/runme.sh @@ -37,3 +37,5 @@ env python -c \ 'import sys, re; sys.stdout.write(re.sub("\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]", "", sys.stdin.read()))' \ block_test_wo_colors.out [ "$(grep -c 'TEST COMPLETE' block_test.out)" = "$(grep -E '^[0-9]+ plays in' block_test_wo_colors.out | cut -f1 -d' ')" ] + +ansible-playbook -vv block_rescue_vars.yml