Move available hosts gathering to a common function

This commit is contained in:
Daniel Hokka Zakrisson 2012-11-28 01:03:18 +01:00
parent 5065103017
commit 9070875a6f

View file

@ -239,10 +239,17 @@ class PlayBook(object):
# ***************************************************** # *****************************************************
def _list_available_hosts(self):
''' returns a list of hosts that haven't failed and aren't dark '''
return [ h for h in self.inventory.list_hosts() 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 = [ h for h in self.inventory.list_hosts() if (h not in self.stats.failures) and (h not in self.stats.dark)] hosts = self._list_available_hosts()
self.inventory.restrict_to(hosts) self.inventory.restrict_to(hosts)
runner = ansible.runner.Runner( runner = ansible.runner.Runner(
@ -340,8 +347,7 @@ class PlayBook(object):
def _do_setup_step(self, play): def _do_setup_step(self, play):
''' get facts from the remote system ''' ''' get facts from the remote system '''
host_list = [ h for h in self.inventory.list_hosts(play.hosts) host_list = self._list_available_hosts()
if not (h in self.stats.failures or h in self.stats.dark) ]
if play.gather_facts is False: if play.gather_facts is False:
return {} return {}
@ -390,8 +396,7 @@ class PlayBook(object):
# now with that data, handle contentional variable file imports! # now with that data, handle contentional variable file imports!
all_hosts = [ h for h in self.inventory.list_hosts(play.hosts) all_hosts = self._list_available_hosts()
if not (h in self.stats.failures or h in self.stats.dark) ]
play.update_vars_files(all_hosts) play.update_vars_files(all_hosts)
serialized_batch = [] serialized_batch = []
@ -426,8 +431,7 @@ 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 = [ h for h in self.inventory.list_hosts(play.hosts) host_list = self._list_available_hosts()
if not (h in self.stats.failures or h in self.stats.dark) ]
# if no hosts remain, drop out # if no hosts remain, drop out
if not host_list: if not host_list: