diff --git a/lib/ansible/executor/play_iterator.py b/lib/ansible/executor/play_iterator.py index f8f3bec9972..57c5a8b4bf8 100644 --- a/lib/ansible/executor/play_iterator.py +++ b/lib/ansible/executor/play_iterator.py @@ -503,6 +503,7 @@ class PlayIterator: s = self._set_failed_state(s) display.debug("^ failed state is now: %s" % s) self._host_states[host.name] = s + self._play._removed_hosts.append(host.name) def get_failed_hosts(self): return dict((host, True) for (host, state) in iteritems(self._host_states) if self._check_failed_state(state)) diff --git a/lib/ansible/playbook/play.py b/lib/ansible/playbook/play.py index de621379720..e3d430f17f4 100644 --- a/lib/ansible/playbook/play.py +++ b/lib/ansible/playbook/play.py @@ -96,6 +96,7 @@ class Play(Base, Taggable, Become): super(Play, self).__init__() self._included_path = None + self._removed_hosts = [] self.ROLE_CACHE = {} def __repr__(self): diff --git a/lib/ansible/plugins/strategy/__init__.py b/lib/ansible/plugins/strategy/__init__.py index bfe891129dc..53d90a0263d 100644 --- a/lib/ansible/plugins/strategy/__init__.py +++ b/lib/ansible/plugins/strategy/__init__.py @@ -365,6 +365,7 @@ class StrategyBase: self._tqm.send_callback('v2_runner_on_failed', task_result, ignore_errors=original_task.ignore_errors) elif task_result.is_unreachable(): self._tqm._unreachable_hosts[original_host.name] = True + iterator._play._removed_hosts.append(original_host.name) self._tqm._stats.increment('dark', original_host.name) self._tqm.send_callback('v2_runner_on_unreachable', task_result) elif task_result.is_skipped(): diff --git a/lib/ansible/vars/__init__.py b/lib/ansible/vars/__init__.py index 8dcb60ab32f..4d2676c3ea4 100644 --- a/lib/ansible/vars/__init__.py +++ b/lib/ansible/vars/__init__.py @@ -410,12 +410,13 @@ class VariableManager: variables['inventory_file'] = self._inventory.src() if play: # add the list of hosts in the play, as adjusted for limit/filters - # DEPRECATED: play_hosts should be deprecated in favor of ansible_play_hosts, - # however this would take work in the templating engine, so for now - # we'll add both so we can give users something transitional to use - variables['play_hosts'] = [x.name for x in self._inventory.get_hosts()] - variables['ansible_play_batch'] = [x.name for x in self._inventory.get_hosts()] - variables['ansible_play_hosts'] = [x.name for x in self._inventory.get_hosts(pattern=play.hosts or 'all', ignore_restrictions=True)] + variables['ansible_play_hosts_all'] = [x.name for x in self._inventory.get_hosts(pattern=play.hosts or 'all', ignore_restrictions=True)] + variables['ansible_play_hosts'] = [x for x in variables['ansible_play_hosts_all'] if x not in play._removed_hosts] + variables['ansible_play_batch'] = [x.name for x in self._inventory.get_hosts() if x.name not in play._removed_hosts] + + #DEPRECATED: play_hosts should be deprecated in favor of ansible_play_batch, + # however this would take work in the templating engine, so for now we'll add both + variables['play_hosts'] = variables['ansible_play_batch'] # the 'omit' value alows params to be left out if the variable they are based on is undefined variables['omit'] = self._omit_token