1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

warn when name is overloaded as both host and group

added small optimization to base group comparisson
fixes #6545
This commit is contained in:
Brian Coca 2017-03-10 18:08:51 -05:00 committed by Brian Coca
parent 19511971ee
commit 0897ec9938

View file

@ -119,6 +119,7 @@ class Inventory(object):
ungrouped = Group('ungrouped') ungrouped = Group('ungrouped')
all = Group('all') all = Group('all')
all.add_child_group(ungrouped) all.add_child_group(ungrouped)
base_groups = frozenset([all, ungrouped])
self.groups = dict(all=all, ungrouped=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) ] 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 # set group vars from group_vars/ files and vars plugins
for g in self.groups: for g in self.groups:
group = self.groups[g] group = self.groups[g]
group.vars = combine_vars(group.vars, self.get_group_variables(group.name)) group.vars = combine_vars(group.vars, self.get_group_variables(group.name))
self.get_group_vars(group) self.get_group_vars(group)
group_names.add(group.name)
host_names = set()
# get host vars from host_vars/ files and vars plugins # get host vars from host_vars/ files and vars plugins
for host in self.get_hosts(ignore_limits=True, ignore_restrictions=True): for host in self.get_hosts(ignore_limits=True, ignore_restrictions=True):
host.vars = combine_vars(host.vars, self.get_host_variables(host.name)) host.vars = combine_vars(host.vars, self.get_host_variables(host.name))
self.get_host_vars(host) self.get_host_vars(host)
host_names.add(host.name)
mygroups = host.get_groups() mygroups = host.get_groups()
@ -178,7 +185,7 @@ class Inventory(object):
if ungrouped in mygroups: if ungrouped in mygroups:
# clear ungrouped of any incorrectly stored by parser # 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) host.remove_group(ungrouped)
else: else:
# add ungrouped hosts to ungrouped # add ungrouped hosts to ungrouped
@ -186,6 +193,9 @@ class Inventory(object):
if length == 0 or (length == 1 and all in mygroups): if length == 0 or (length == 1 and all in mygroups):
ungrouped.add_host(host) 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): def _match(self, str, pattern_str):
try: try: