summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Krizek <martin.krizek@gmail.com>2019-11-14 15:50:54 +0100
committerGitHub <noreply@github.com>2019-11-14 15:50:54 +0100
commit5c0b2c151ce7d7f2a4df2f1525d3eb6302a2e790 (patch)
tree08b1a09a6a4c04ba2270671ffac86e9edd9a09f6
parentf17a55a181171d508d0d15b5156780f338e90acc (diff)
downloadansible-5c0b2c151ce7d7f2a4df2f1525d3eb6302a2e790.tar.gz
Fix ansible_failed_{task,result} undefined in rescue (#64831)
This is a fix for a regression introduced by Perfy. Since then we mainly operate on host.name instead of the Host object. In a call to set_nonpersistent_facts where we set ansible_failed_task and ansible_failed_result variables we were still passing the object which led to those vars being undefined. Fixes #64789
-rw-r--r--changelogs/fragments/64789-regression-rescue-vars-not-defined.yml2
-rw-r--r--lib/ansible/plugins/strategy/__init__.py2
-rw-r--r--test/integration/targets/blocks/block_rescue_vars.yml16
-rwxr-xr-xtest/integration/targets/blocks/runme.sh2
4 files changed, 21 insertions, 1 deletions
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 0000000000..2ae04ae74b
--- /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 5f6974cea0..2275e5590d 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 0000000000..404f7a3792
--- /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 3384bb9d9b..f158735611 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.out >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