Fix issue with same host and group names

When host and group name is the same, the inventory fails to run.
Use different method of adding host to inventory with this case.

Fixes rhbz#2017495
Change-Id: Iad288c3c11d0791be33b379554577eab8381b44d
This commit is contained in:
Sagi Shnaidman 2021-11-02 11:39:23 +02:00
parent 59d0e4c3a4
commit 11c7cd23f8
1 changed files with 5 additions and 1 deletions

View File

@ -311,7 +311,11 @@ class InventoryModule(BaseInventoryPlugin, Constructable, Cacheable):
for group_name, group_hosts in groups.items():
gname = self.inventory.add_group(group_name)
for host in group_hosts:
self.inventory.add_child(gname, host)
if gname == host:
display.vvvv("Same name for host %s and group %s" % (host, gname))
self.inventory.add_host(host, gname)
else:
self.inventory.add_child(gname, host)
def _get_groups_from_server(self, server_vars, namegroup=True):
groups = []