diff --git a/lib/ansible/playbook/__init__.py b/lib/ansible/playbook/__init__.py index af234a1f77c..5dd81b094cf 100644 --- a/lib/ansible/playbook/__init__.py +++ b/lib/ansible/playbook/__init__.py @@ -316,7 +316,8 @@ class PlayBook(object): check=self.check, diff=self.diff, environment=task.environment, complex_args=task.args, accelerate=task.play.accelerate, accelerate_port=task.play.accelerate_port, accelerate_ipv6=task.play.accelerate_ipv6, - error_on_undefined_vars=C.DEFAULT_UNDEFINED_VAR_BEHAVIOR + error_on_undefined_vars=C.DEFAULT_UNDEFINED_VAR_BEHAVIOR, + run_hosts=hosts ) if task.async_seconds == 0: diff --git a/lib/ansible/runner/__init__.py b/lib/ansible/runner/__init__.py index ef8d4aac211..c195cefe24e 100644 --- a/lib/ansible/runner/__init__.py +++ b/lib/ansible/runner/__init__.py @@ -141,6 +141,7 @@ class Runner(object): accelerate=False, # use accelerated connection accelerate_ipv6=False, # accelerated connection w/ IPv6 accelerate_port=None, # port to use with accelerated connection + run_hosts=None, # an optional list of pre-calculated hosts to run on ): # used to lock multiprocess inputs and outputs at various levels @@ -205,6 +206,10 @@ class Runner(object): # don't override subset when passed from playbook self.inventory.subset(subset) + # If we get a pre-built list of hosts to run on, from say a playbook, use them. + # Also where we will store the hosts to run on once discovered + self.run_hosts = run_hosts + if self.transport == 'local': self.remote_user = pwd.getpwuid(os.geteuid())[0] @@ -1002,7 +1007,7 @@ class Runner(object): results2["dark"][host] = result.result # hosts which were contacted but never got a chance to return - for host in self.inventory.list_hosts(self.pattern): + for host in self.run_hosts: if not (host in results2['dark'] or host in results2['contacted']): results2["dark"][host] = {} return results2 @@ -1013,7 +1018,9 @@ class Runner(object): ''' xfer & run module on all matched hosts ''' # find hosts that match the pattern - hosts = self.inventory.list_hosts(self.pattern) + if not self.run_hosts: + self.run_hosts = self.inventory.list_hosts(self.pattern) + hosts = self.run_hosts if len(hosts) == 0: self.callbacks.on_no_hosts() return dict(contacted={}, dark={})