mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
inventory groups: make sure group.depth is updated on all grandchildren
This commit is contained in:
parent
1c86909875
commit
cc8efb4aab
2 changed files with 11 additions and 1 deletions
|
@ -68,7 +68,6 @@ class InventoryDirectory(object):
|
|||
self.groups[name] = group
|
||||
else:
|
||||
# group is already there, copy variables
|
||||
# note: depth numbers on duplicates may be bogus
|
||||
for k, v in group.get_variables().iteritems():
|
||||
self.groups[name].set_variable(k, v)
|
||||
for host in group.hosts:
|
||||
|
|
|
@ -40,8 +40,13 @@ class Group(object):
|
|||
# don't add if it's already there
|
||||
if not group in self.child_groups:
|
||||
self.child_groups.append(group)
|
||||
|
||||
# update the depth of the child
|
||||
group.depth = max([self.depth+1, group.depth])
|
||||
|
||||
# update the depth of the grandchildren
|
||||
group._check_children_depth()
|
||||
|
||||
# now add self to child's parent_groups list, but only if there
|
||||
# isn't already a group with the same name
|
||||
if not self.name in [g.name for g in group.parent_groups]:
|
||||
|
@ -49,6 +54,12 @@ class Group(object):
|
|||
|
||||
self.clear_hosts_cache()
|
||||
|
||||
def _check_children_depth(self):
|
||||
|
||||
for group in self.child_groups:
|
||||
group.depth = max([self.depth+1, group.depth])
|
||||
group._check_children_depth()
|
||||
|
||||
def add_host(self, host):
|
||||
|
||||
self.hosts.append(host)
|
||||
|
|
Loading…
Reference in a new issue