From f1cf81b08641b64625d50024144a1c7a986d8470 Mon Sep 17 00:00:00 2001 From: Serge van Ginderachter Date: Mon, 3 Jun 2013 22:35:07 +0200 Subject: [PATCH] optimization when adding child groups --- lib/ansible/inventory/group.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/ansible/inventory/group.py b/lib/ansible/inventory/group.py index 6f06cb0762..61ef1342bd 100644 --- a/lib/ansible/inventory/group.py +++ b/lib/ansible/inventory/group.py @@ -35,9 +35,12 @@ class Group(object): if self == group: raise Exception("can't add group to itself") - self.child_groups.append(group) - group.depth = max([self.depth+1, group.depth]) - group.parent_groups.append(self) + + # don't add if it's already there + if not group in self.child_groups: + self.child_groups.append(group) + group.depth = max([self.depth+1, group.depth]) + group.parent_groups.append(self) def add_host(self, host):