From cc8efb4aabeb1aafd8f0ec470ce82d4395eec8bf Mon Sep 17 00:00:00 2001 From: Serge van Ginderachter Date: Wed, 5 Mar 2014 16:43:48 +0100 Subject: [PATCH] inventory groups: make sure group.depth is updated on all grandchildren --- lib/ansible/inventory/dir.py | 1 - lib/ansible/inventory/group.py | 11 +++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/ansible/inventory/dir.py b/lib/ansible/inventory/dir.py index 39f45f0920..74a8eacba9 100644 --- a/lib/ansible/inventory/dir.py +++ b/lib/ansible/inventory/dir.py @@ -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: diff --git a/lib/ansible/inventory/group.py b/lib/ansible/inventory/group.py index 94ee8eceba..eb2eb45ea3 100644 --- a/lib/ansible/inventory/group.py +++ b/lib/ansible/inventory/group.py @@ -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)