diff --git a/bin/ansible-playbook b/bin/ansible-playbook index 91380b6fa4..2332e08567 100755 --- a/bin/ansible-playbook +++ b/bin/ansible-playbook @@ -122,9 +122,11 @@ def main(args): print '\n' return 0 + try: pb.run() + hosts = sorted(pb.stats.processed.keys()) print callbacks.banner("PLAY RECAP") playbook_cb.on_stats(pb.stats) diff --git a/lib/ansible/callbacks.py b/lib/ansible/callbacks.py index 8feed2907f..4fe2523fc6 100644 --- a/lib/ansible/callbacks.py +++ b/lib/ansible/callbacks.py @@ -376,7 +376,7 @@ class PlaybookRunnerCallbacks(DefaultRunnerCallbacks): super(PlaybookRunnerCallbacks, self).on_skipped(host, item) 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() def on_async_poll(self, host, res, jid, clock): diff --git a/lib/ansible/playbook/__init__.py b/lib/ansible/playbook/__init__.py index 671b7455e3..f591920468 100644 --- a/lib/ansible/playbook/__init__.py +++ b/lib/ansible/playbook/__init__.py @@ -181,7 +181,8 @@ class PlayBook(object): raise errors.AnsibleError(msg % (unknown, unmatched)) for play in plays: - self._run_play(play) + if not self._run_play(play): + break # summarize the results results = {} @@ -360,16 +361,12 @@ class PlayBook(object): play_hosts.append(all_hosts.pop()) serialized_batch.append(play_hosts) - hosts_remaining = True for on_hosts in serialized_batch: self.inventory.also_restrict_to(on_hosts) for task in play.tasks(): - if not hosts_remaining: - continue - # only run the task if the requested tags match should_run = False for x in self.only_tags: @@ -379,16 +376,15 @@ class PlayBook(object): break if should_run: if not self._run_task(play, task, False): - hosts_remaining = False + return False # run notify actions for handler in play.handlers(): - if not hosts_remaining: - continue if len(handler.notified_by) > 0: self.inventory.restrict_to(handler.notified_by) self._run_task(play, handler, True) self.inventory.lift_restriction() self.inventory.lift_also_restriction() + return True