From 924e0726df4340b94ac996487a57c98570315223 Mon Sep 17 00:00:00 2001 From: James Cammarata Date: Mon, 17 Oct 2016 15:49:57 -0500 Subject: [PATCH] Break out of linear strategy if all hosts are failed and the result is not OK Fixes #18021 (cherry picked from commit 5be2a3a9e03afa9734fb41c1f47a9f639c440120) --- lib/ansible/plugins/strategy/linear.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/ansible/plugins/strategy/linear.py b/lib/ansible/plugins/strategy/linear.py index 3acd58832c3..95ca7a6f06b 100644 --- a/lib/ansible/plugins/strategy/linear.py +++ b/lib/ansible/plugins/strategy/linear.py @@ -395,7 +395,8 @@ class StrategyModule(StrategyBase): if any_errors_fatal and (len(failed_hosts) > 0 or len(unreachable_hosts) > 0): for host in hosts_left: (s, _) = iterator.get_next_task_for_host(host, peek=True) - if s.run_state != iterator.ITERATING_RESCUE: + if s.run_state != iterator.ITERATING_RESCUE or \ + s.run_state == iterator.ITERATING_RESCUE and s.fail_state & iterator.FAILED_RESCUE != 0: self._tqm._failed_hosts[host.name] = True result |= self._tqm.RUN_FAILED_BREAK_PLAY display.debug("done checking for any_errors_fatal") @@ -415,6 +416,13 @@ class StrategyModule(StrategyBase): result |= self._tqm.RUN_FAILED_BREAK_PLAY display.debug("done checking for max_fail_percentage") + display.debug("checking to see if all hosts have failed and the running result is not ok") + if result != self._tqm.RUN_OK and len(self._tqm._failed_hosts) >= len(hosts_left): + display.debug("^ not ok, so returning result now") + self._tqm.send_callback('v2_playbook_on_no_hosts_remaining') + return result + display.debug("done checking to see if all hosts have failed") + except (IOError, EOFError) as e: display.debug("got IOError/EOFError in task loop: %s" % e) # most likely an abort, return failed