Ensure hosts aren't duplicated in groups

This commit is contained in:
Matt Martz 2017-06-19 15:12:35 -05:00 committed by Brian Coca
parent 9730d96517
commit b6ee9163e3
2 changed files with 3 additions and 2 deletions

View file

@ -231,7 +231,7 @@ class InventoryData(object):
else: else:
h = self.hosts[host] h = self.hosts[host]
if g and host not in g.get_hosts(): if g and h not in g.get_hosts():
g.add_host(h) g.add_host(h)
self._groups_dict_cache = {} self._groups_dict_cache = {}
display.debug("Added host %s to group %s" % (host, group)) display.debug("Added host %s to group %s" % (host, group))

View file

@ -112,7 +112,8 @@ class Group:
raise AnsibleError("The group named '%s' has a recursive dependency loop." % self.name) raise AnsibleError("The group named '%s' has a recursive dependency loop." % self.name)
def add_host(self, host): def add_host(self, host):
if host in self.hosts:
return
self.hosts.append(host) self.hosts.append(host)
host.add_group(self) host.add_group(self)
self.clear_hosts_cache() self.clear_hosts_cache()