mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Be smarter about when to abort a playbook -- if it's early, we just didn't match any hosts, so keep on, hosts might be dynamic.
This commit is contained in:
parent
35de8da108
commit
5683277e4a
2 changed files with 10 additions and 2 deletions
|
@ -376,7 +376,7 @@ class PlaybookRunnerCallbacks(DefaultRunnerCallbacks):
|
|||
super(PlaybookRunnerCallbacks, self).on_skipped(host, item)
|
||||
|
||||
def on_no_hosts(self):
|
||||
print stringc("FATAL: no hosts matched or all hosts have already failed -- aborting playbook\n", 'red')
|
||||
print stringc("FATAL: no hosts matched or all hosts have already failed -- aborting\n", 'red')
|
||||
super(PlaybookRunnerCallbacks, self).on_no_hosts()
|
||||
|
||||
def on_async_poll(self, host, res, jid, clock):
|
||||
|
|
|
@ -115,6 +115,9 @@ class PlayBook(object):
|
|||
(self.playbook, self.play_basedirs) = self._load_playbook_from_file(playbook)
|
||||
self.module_path = self.module_path + os.pathsep + os.path.join(self.basedir, "library")
|
||||
|
||||
# which task we are currently executing
|
||||
self.task_counter = 0
|
||||
|
||||
# *****************************************************
|
||||
|
||||
def _load_playbook_from_file(self, path):
|
||||
|
@ -236,6 +239,8 @@ class PlayBook(object):
|
|||
# if not polling, playbook requested fire and forget, so don't poll
|
||||
results = self._async_poll(poller, task.async_seconds, task.async_poll_interval)
|
||||
|
||||
self.task_counter = self.task_counter + 1
|
||||
|
||||
contacted = results.get('contacted',{})
|
||||
dark = results.get('dark', {})
|
||||
|
||||
|
@ -376,7 +381,10 @@ class PlayBook(object):
|
|||
break
|
||||
if should_run:
|
||||
if not self._run_task(play, task, False):
|
||||
return False
|
||||
# whether no hosts matched is fatal or not depends if it was on the initial step.
|
||||
# if we got exactly no hosts on the first step (setup!) then the host group
|
||||
# just didn't match anything and that's ok
|
||||
return (self.task_counter <= 1)
|
||||
|
||||
# run notify actions
|
||||
for handler in play.handlers():
|
||||
|
|
Loading…
Reference in a new issue