summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/ansible/plugins/strategy/__init__.py14
1 files changed, 14 insertions, 0 deletions
diff --git a/lib/ansible/plugins/strategy/__init__.py b/lib/ansible/plugins/strategy/__init__.py
index f8349ea744..925bb9c982 100644
--- a/lib/ansible/plugins/strategy/__init__.py
+++ b/lib/ansible/plugins/strategy/__init__.py
@@ -216,6 +216,20 @@ class StrategyBase:
if iterator.is_failed(host):
self._tqm._failed_hosts[host.name] = True
self._tqm._stats.increment('failures', host.name)
+ else:
+ # otherwise, we grab the current state and if we're iterating on
+ # the rescue portion of a block then we save the failed task in a
+ # special var for use within the rescue/always
+ state, _ = iterator.get_next_task_for_host(host, peek=True)
+ if state.run_state == iterator.ITERATING_RESCUE:
+ original_task = iterator.get_original_task(host, task)
+ self._variable_manager.set_nonpersistent_facts(
+ host,
+ dict(
+ ansible_failed_task=original_task.serialize(),
+ ansible_failed_result=task_result._result,
+ ),
+ )
else:
self._tqm._stats.increment('ok', host.name)
self._tqm.send_callback('v2_runner_on_failed', task_result, ignore_errors=task.ignore_errors)