|
|
@ -296,17 +296,17 @@ class PlayBook(object):
|
|
|
|
|
|
|
|
|
|
|
|
# *****************************************************
|
|
|
|
# *****************************************************
|
|
|
|
|
|
|
|
|
|
|
|
def _list_available_hosts(self, *args):
|
|
|
|
def _trim_unavailable_hosts(self, hostlist=[]):
|
|
|
|
''' returns a list of hosts that haven't failed and aren't dark '''
|
|
|
|
''' returns a list of hosts that haven't failed and aren't dark '''
|
|
|
|
|
|
|
|
|
|
|
|
return [ h for h in self.inventory.list_hosts(*args) if (h not in self.stats.failures) and (h not in self.stats.dark)]
|
|
|
|
return [ h for h in hostlist if (h not in self.stats.failures) and (h not in self.stats.dark)]
|
|
|
|
|
|
|
|
|
|
|
|
# *****************************************************
|
|
|
|
# *****************************************************
|
|
|
|
|
|
|
|
|
|
|
|
def _run_task_internal(self, task):
|
|
|
|
def _run_task_internal(self, task):
|
|
|
|
''' run a particular module step in a playbook '''
|
|
|
|
''' run a particular module step in a playbook '''
|
|
|
|
|
|
|
|
|
|
|
|
hosts = self._list_available_hosts()
|
|
|
|
hosts = self._trim_unavailable_hosts(task.play._play_hosts)
|
|
|
|
self.inventory.restrict_to(hosts)
|
|
|
|
self.inventory.restrict_to(hosts)
|
|
|
|
|
|
|
|
|
|
|
|
runner = ansible.runner.Runner(
|
|
|
|
runner = ansible.runner.Runner(
|
|
|
@ -342,7 +342,8 @@ class PlayBook(object):
|
|
|
|
error_on_undefined_vars=C.DEFAULT_UNDEFINED_VAR_BEHAVIOR,
|
|
|
|
error_on_undefined_vars=C.DEFAULT_UNDEFINED_VAR_BEHAVIOR,
|
|
|
|
su=task.su,
|
|
|
|
su=task.su,
|
|
|
|
su_user=task.su_user,
|
|
|
|
su_user=task.su_user,
|
|
|
|
su_pass=task.su_pass
|
|
|
|
su_pass=task.su_pass,
|
|
|
|
|
|
|
|
run_hosts=hosts
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
if task.async_seconds == 0:
|
|
|
|
if task.async_seconds == 0:
|
|
|
@ -462,7 +463,7 @@ class PlayBook(object):
|
|
|
|
if play.gather_facts is False:
|
|
|
|
if play.gather_facts is False:
|
|
|
|
return {}
|
|
|
|
return {}
|
|
|
|
|
|
|
|
|
|
|
|
host_list = self._list_available_hosts(play.hosts)
|
|
|
|
host_list = self._trim_unavailable_hosts(play._play_hosts)
|
|
|
|
|
|
|
|
|
|
|
|
self.callbacks.on_setup()
|
|
|
|
self.callbacks.on_setup()
|
|
|
|
self.inventory.restrict_to(host_list)
|
|
|
|
self.inventory.restrict_to(host_list)
|
|
|
@ -542,8 +543,10 @@ class PlayBook(object):
|
|
|
|
''' run a list of tasks for a given pattern, in order '''
|
|
|
|
''' run a list of tasks for a given pattern, in order '''
|
|
|
|
|
|
|
|
|
|
|
|
self.callbacks.on_play_start(play.name)
|
|
|
|
self.callbacks.on_play_start(play.name)
|
|
|
|
|
|
|
|
# Get the hosts for this play
|
|
|
|
|
|
|
|
play._play_hosts = self.inventory.list_hosts(play.hosts)
|
|
|
|
# if no hosts matches this play, drop out
|
|
|
|
# if no hosts matches this play, drop out
|
|
|
|
if not self.inventory.list_hosts(play.hosts):
|
|
|
|
if not play._play_hosts:
|
|
|
|
self.callbacks.on_no_hosts_matched()
|
|
|
|
self.callbacks.on_no_hosts_matched()
|
|
|
|
return True
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
|
@ -552,8 +555,9 @@ class PlayBook(object):
|
|
|
|
|
|
|
|
|
|
|
|
# now with that data, handle contentional variable file imports!
|
|
|
|
# now with that data, handle contentional variable file imports!
|
|
|
|
|
|
|
|
|
|
|
|
all_hosts = self._list_available_hosts(play.hosts)
|
|
|
|
all_hosts = self._trim_unavailable_hosts(play._play_hosts)
|
|
|
|
play.update_vars_files(all_hosts)
|
|
|
|
play.update_vars_files(all_hosts)
|
|
|
|
|
|
|
|
hosts_count = len(all_hosts)
|
|
|
|
|
|
|
|
|
|
|
|
serialized_batch = []
|
|
|
|
serialized_batch = []
|
|
|
|
if play.serial <= 0:
|
|
|
|
if play.serial <= 0:
|
|
|
@ -569,6 +573,9 @@ class PlayBook(object):
|
|
|
|
|
|
|
|
|
|
|
|
for on_hosts in serialized_batch:
|
|
|
|
for on_hosts in serialized_batch:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# restrict the play to just the hosts we have in our on_hosts block that are
|
|
|
|
|
|
|
|
# available.
|
|
|
|
|
|
|
|
play._play_hosts = self._trim_unavailable_hosts(on_hosts)
|
|
|
|
self.inventory.also_restrict_to(on_hosts)
|
|
|
|
self.inventory.also_restrict_to(on_hosts)
|
|
|
|
|
|
|
|
|
|
|
|
for task in play.tasks():
|
|
|
|
for task in play.tasks():
|
|
|
@ -591,7 +598,7 @@ class PlayBook(object):
|
|
|
|
# prevent duplicate handler includes from running more than once
|
|
|
|
# prevent duplicate handler includes from running more than once
|
|
|
|
fired_names[handler_name] = 1
|
|
|
|
fired_names[handler_name] = 1
|
|
|
|
|
|
|
|
|
|
|
|
host_list = self._list_available_hosts(play.hosts)
|
|
|
|
host_list = self._trim_unavailable_hosts(play._play_hosts)
|
|
|
|
if handler.any_errors_fatal and len(host_list) < hosts_count:
|
|
|
|
if handler.any_errors_fatal and len(host_list) < hosts_count:
|
|
|
|
play.max_fail_pct = 0
|
|
|
|
play.max_fail_pct = 0
|
|
|
|
if (hosts_count - len(host_list)) > int((play.max_fail_pct)/100.0 * hosts_count):
|
|
|
|
if (hosts_count - len(host_list)) > int((play.max_fail_pct)/100.0 * hosts_count):
|
|
|
@ -610,8 +617,6 @@ class PlayBook(object):
|
|
|
|
|
|
|
|
|
|
|
|
continue
|
|
|
|
continue
|
|
|
|
|
|
|
|
|
|
|
|
hosts_count = len(self._list_available_hosts(play.hosts))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 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:
|
|
|
@ -634,7 +639,9 @@ class PlayBook(object):
|
|
|
|
# just didn't match anything and that's ok
|
|
|
|
# just didn't match anything and that's ok
|
|
|
|
return False
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
|
|
host_list = self._list_available_hosts(play.hosts)
|
|
|
|
# Get a new list of what hosts are left as available, the ones that
|
|
|
|
|
|
|
|
# did not go fail/dark during the task
|
|
|
|
|
|
|
|
host_list = self._trim_unavailable_hosts(play._play_hosts)
|
|
|
|
|
|
|
|
|
|
|
|
# Set max_fail_pct to 0, So if any hosts fails, bail out
|
|
|
|
# Set max_fail_pct to 0, So if any hosts fails, bail out
|
|
|
|
if task.any_errors_fatal and len(host_list) < hosts_count:
|
|
|
|
if task.any_errors_fatal and len(host_list) < hosts_count:
|
|
|
|