mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-04-24 19:31:26 -07:00
Don't immediately return failed for any_errors_fatal tasks
Instead of immediately returning a failed code (indicating a break in the play execution), we internally 'or' that failure code with the result (now an integer flag instead of a boolean) so that we can properly handle the rescue/always portions of blocks and still remember that the break condition was hit. Fixes #16937
This commit is contained in:
parent
b44eb402bd
commit
c669a381d1
5 changed files with 26 additions and 25 deletions
|
@ -157,7 +157,7 @@ class StrategyModule(StrategyBase):
|
|||
'''
|
||||
|
||||
# iteratate over each task, while there is one left to run
|
||||
result = True
|
||||
result = self._tqm.RUN_OK
|
||||
work_to_do = True
|
||||
while work_to_do and not self._tqm._terminated:
|
||||
|
||||
|
@ -269,12 +269,6 @@ class StrategyModule(StrategyBase):
|
|||
results += self._wait_on_pending_results(iterator)
|
||||
host_results.extend(results)
|
||||
|
||||
if not work_to_do and len(iterator.get_failed_hosts()) > 0:
|
||||
display.debug("out of hosts to run on")
|
||||
self._tqm.send_callback('v2_playbook_on_no_hosts_remaining')
|
||||
result = self._tqm.RUN_ERROR
|
||||
break
|
||||
|
||||
try:
|
||||
included_files = IncludedFile.process_include_results(
|
||||
host_results,
|
||||
|
@ -285,6 +279,7 @@ class StrategyModule(StrategyBase):
|
|||
variable_manager=self._variable_manager
|
||||
)
|
||||
except AnsibleError as e:
|
||||
# this is a fatal error, so we abort here regardless of block state
|
||||
return self._tqm.RUN_ERROR
|
||||
|
||||
include_failure = False
|
||||
|
@ -360,13 +355,10 @@ class StrategyModule(StrategyBase):
|
|||
# if any_errors_fatal and we had an error, mark all hosts as failed
|
||||
if any_errors_fatal and (len(failed_hosts) > 0 or len(unreachable_hosts) > 0):
|
||||
for host in hosts_left:
|
||||
# don't double-mark hosts, or the iterator will potentially
|
||||
# fail them out of the rescue/always states
|
||||
if host.name not in failed_hosts:
|
||||
(s, _) = iterator.get_next_task_for_host(host, peek=True)
|
||||
if s.run_state != iterator.ITERATING_RESCUE:
|
||||
self._tqm._failed_hosts[host.name] = True
|
||||
iterator.mark_host_failed(host)
|
||||
self._tqm.send_callback('v2_playbook_on_no_hosts_remaining')
|
||||
return self._tqm.RUN_FAILED_BREAK_PLAY
|
||||
result |= self._tqm.RUN_FAILED_BREAK_PLAY
|
||||
display.debug("done checking for any_errors_fatal")
|
||||
|
||||
display.debug("checking for max_fail_percentage")
|
||||
|
@ -381,7 +373,7 @@ class StrategyModule(StrategyBase):
|
|||
self._tqm._failed_hosts[host.name] = True
|
||||
iterator.mark_host_failed(host)
|
||||
self._tqm.send_callback('v2_playbook_on_no_hosts_remaining')
|
||||
return self._tqm.RUN_FAILED_BREAK_PLAY
|
||||
result |= self._tqm.RUN_FAILED_BREAK_PLAY
|
||||
display.debug("done checking for max_fail_percentage")
|
||||
|
||||
except (IOError, EOFError) as e:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue