1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

If all hosts in a play fail, fail the whole playbook and don't bother printing out every remaining task.

This commit is contained in:
Michael DeHaan 2012-09-30 21:06:00 -04:00
parent 22f3aef4dc
commit a2f76c1c69
3 changed files with 7 additions and 9 deletions

View file

@ -122,9 +122,11 @@ def main(args):
print '\n' print '\n'
return 0 return 0
try: try:
pb.run() pb.run()
hosts = sorted(pb.stats.processed.keys()) hosts = sorted(pb.stats.processed.keys())
print callbacks.banner("PLAY RECAP") print callbacks.banner("PLAY RECAP")
playbook_cb.on_stats(pb.stats) playbook_cb.on_stats(pb.stats)

View file

@ -376,7 +376,7 @@ class PlaybookRunnerCallbacks(DefaultRunnerCallbacks):
super(PlaybookRunnerCallbacks, self).on_skipped(host, item) super(PlaybookRunnerCallbacks, self).on_skipped(host, item)
def on_no_hosts(self): def on_no_hosts(self):
print stringc("no hosts matched or remaining\n", 'red') print stringc("FATAL: no hosts matched or all hosts have already failed -- aborting playbook\n", 'red')
super(PlaybookRunnerCallbacks, self).on_no_hosts() super(PlaybookRunnerCallbacks, self).on_no_hosts()
def on_async_poll(self, host, res, jid, clock): def on_async_poll(self, host, res, jid, clock):

View file

@ -181,7 +181,8 @@ class PlayBook(object):
raise errors.AnsibleError(msg % (unknown, unmatched)) raise errors.AnsibleError(msg % (unknown, unmatched))
for play in plays: for play in plays:
self._run_play(play) if not self._run_play(play):
break
# summarize the results # summarize the results
results = {} results = {}
@ -360,16 +361,12 @@ class PlayBook(object):
play_hosts.append(all_hosts.pop()) play_hosts.append(all_hosts.pop())
serialized_batch.append(play_hosts) serialized_batch.append(play_hosts)
hosts_remaining = True
for on_hosts in serialized_batch: for on_hosts in serialized_batch:
self.inventory.also_restrict_to(on_hosts) self.inventory.also_restrict_to(on_hosts)
for task in play.tasks(): for task in play.tasks():
if not hosts_remaining:
continue
# only run the task if the requested tags match # only run the task if the requested tags match
should_run = False should_run = False
for x in self.only_tags: for x in self.only_tags:
@ -379,16 +376,15 @@ class PlayBook(object):
break break
if should_run: if should_run:
if not self._run_task(play, task, False): if not self._run_task(play, task, False):
hosts_remaining = False return False
# run notify actions # run notify actions
for handler in play.handlers(): for handler in play.handlers():
if not hosts_remaining:
continue
if len(handler.notified_by) > 0: if len(handler.notified_by) > 0:
self.inventory.restrict_to(handler.notified_by) self.inventory.restrict_to(handler.notified_by)
self._run_task(play, handler, True) self._run_task(play, handler, True)
self.inventory.lift_restriction() self.inventory.lift_restriction()
self.inventory.lift_also_restriction() self.inventory.lift_also_restriction()
return True