From c52abd40b034d68bdf7c501ad7523830ce9e4c70 Mon Sep 17 00:00:00 2001 From: Michael DeHaan Date: Mon, 3 Jun 2013 11:41:11 -0400 Subject: [PATCH] Fix for the directory inventory source where depth information on the group was being discarded due to initial copy. New model will reuse the first object and copy attributes on the second. --- lib/ansible/inventory/dir.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/lib/ansible/inventory/dir.py b/lib/ansible/inventory/dir.py index 0db6ba2dff..ac1e2aa5bf 100644 --- a/lib/ansible/inventory/dir.py +++ b/lib/ansible/inventory/dir.py @@ -62,15 +62,22 @@ class InventoryDirectory(object): # This takes a lot of code because we can't directly use any of the objects, as they have to blend for name, group in parser.groups.iteritems(): if name not in self.groups: - self.groups[name] = Group(name) - for k, v in group.get_variables().iteritems(): - self.groups[name].set_variable(k, v) + 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.get_hosts(): if host.name not in self.hosts: - self.hosts[host.name] = Host(host.name) - for k, v in host.vars.iteritems(): - self.hosts[host.name].set_variable(k, v) + self.hosts[host.name] = host + else: + # host is already there, copy variables + # note: depth numbers on duplicates may be bogus + for k, v in host.vars.iteritems(): + self.hosts[host.name].set_variable(k, v) self.groups[name].add_host(self.hosts[host.name]) + # This needs to be a second loop to ensure all the parent groups exist for name, group in parser.groups.iteritems(): for ancestor in group.get_ancestors():