summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrian Coca <brian.coca+git@gmail.com>2017-03-10 18:08:51 -0500
committerBrian Coca <bcoca@users.noreply.github.com>2017-03-13 17:41:25 -0400
commit0897ec9938c234fdd693b076ec8c6263dee66d90 (patch)
tree5fbc3689e2d315bcfd8031b9b036df18a8669d4b
parent19511971eefc12ccb23c56a17e7930eed3b65409 (diff)
downloadansible-0897ec9938c234fdd693b076ec8c6263dee66d90.tar.gz
warn when name is overloaded as both host and group
added small optimization to base group comparisson fixes #6545
-rw-r--r--lib/ansible/inventory/__init__.py12
1 files changed, 11 insertions, 1 deletions
diff --git a/lib/ansible/inventory/__init__.py b/lib/ansible/inventory/__init__.py
index fa8fea6bae..73ed23a832 100644
--- a/lib/ansible/inventory/__init__.py
+++ b/lib/ansible/inventory/__init__.py
@@ -119,6 +119,7 @@ class Inventory(object):
ungrouped = Group('ungrouped')
all = Group('all')
all.add_child_group(ungrouped)
+ base_groups = frozenset([all, ungrouped])
self.groups = dict(all=all, ungrouped=ungrouped)
@@ -159,16 +160,22 @@ class Inventory(object):
self._vars_plugins = [ x for x in vars_loader.all(self) ]
+ ### POST PROCESS groups and hosts after specific parser was invoked
+
+ group_names = set()
# set group vars from group_vars/ files and vars plugins
for g in self.groups:
group = self.groups[g]
group.vars = combine_vars(group.vars, self.get_group_variables(group.name))
self.get_group_vars(group)
+ group_names.add(group.name)
+ host_names = set()
# get host vars from host_vars/ files and vars plugins
for host in self.get_hosts(ignore_limits=True, ignore_restrictions=True):
host.vars = combine_vars(host.vars, self.get_host_variables(host.name))
self.get_host_vars(host)
+ host_names.add(host.name)
mygroups = host.get_groups()
@@ -178,7 +185,7 @@ class Inventory(object):
if ungrouped in mygroups:
# clear ungrouped of any incorrectly stored by parser
- if set(mygroups).difference(set([all, ungrouped])):
+ if set(mygroups).difference(base_groups):
host.remove_group(ungrouped)
else:
# add ungrouped hosts to ungrouped
@@ -186,6 +193,9 @@ class Inventory(object):
if length == 0 or (length == 1 and all in mygroups):
ungrouped.add_host(host)
+ # warn if overloading identifier as both group and host
+ for conflict in group_names.intersection(host_names):
+ display.warning("Found both group and host with same name: %s" % conflict)
def _match(self, str, pattern_str):
try: