diff options
author | Brian Coca <brian.coca+git@gmail.com> | 2017-03-08 14:58:10 -0500 |
---|---|---|
committer | Brian Coca <brian.coca+git@gmail.com> | 2017-03-08 14:58:10 -0500 |
commit | 3ba057d28dab0ae4742cade8a117724ffe490c06 (patch) | |
tree | 5a8ea58ca72021a76eca686c8d3701ee6c58bd7d | |
parent | ac4ce958106b6a01bb4e452689a31a9903f211d8 (diff) | |
download | ansible-3ba057d28dab0ae4742cade8a117724ffe490c06.tar.gz |
backport inventory fix, ensure all/ungrouped
-rw-r--r-- | lib/ansible/inventory/__init__.py | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/lib/ansible/inventory/__init__.py b/lib/ansible/inventory/__init__.py index 1f0317c454..be24eedc0f 100644 --- a/lib/ansible/inventory/__init__.py +++ b/lib/ansible/inventory/__init__.py @@ -21,7 +21,6 @@ __metaclass__ = type import fnmatch import os -import subprocess import sys import re import itertools @@ -140,7 +139,6 @@ class Inventory(object): display.warning("A duplicate localhost-like entry was found (%s). First found localhost was %s" % (h, self.localhost.name)) display.vvvv("Set default localhost to %s" % h) self.localhost = new_host - all.add_host(new_host) elif self._loader.path_exists(host_list): # TODO: switch this to a plugin loader and a 'condition' per plugin on which it should be tried, restoring 'inventory pllugins' if self.is_directory(host_list): @@ -170,6 +168,16 @@ class Inventory(object): host.vars = combine_vars(host.vars, self.get_host_variables(host.name)) self.get_host_vars(host) + mygroups = host.get_groups() + + # ensure hosts are always in 'all' + if all not in mygroups: + all.add_host(host) + + # clear ungrouped of any incorrectly stored by parser + if len(mygroups) > 2 and ungrouped in mygroups: + host.remove_group(ungrouped) + def _match(self, str, pattern_str): try: if pattern_str.startswith('~'): |