mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Adds two variables to facts when a task fails and a rescue block starts
`ansible_failed_task`: Contains the task data, essentially a serialized view of the Task() object. `ansible_failed_result`: Contains the result of the task failure, which is identical in function to registering the result. Doing so automatically like this saves the user from having to register every result in a block and then trying to figure out which result had the failure Similar to the way try/except/finally work, these variables will not be available in the `always` portion of a block unless there is a corresponding `rescue` first. Fixes #12341
This commit is contained in:
parent
26a4761d0f
commit
0656d1466a
1 changed files with 14 additions and 0 deletions
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue