1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

Make sure any existing groups gets reused

This commit is contained in:
Daniel Hokka Zakrisson 2012-11-25 12:42:30 +01:00
parent 5504f13c68
commit 0c70abfaa9
2 changed files with 4 additions and 3 deletions

View file

@ -67,9 +67,10 @@ class InventoryParser(object):
active_group_name = line.replace("[","").replace("]","").strip() active_group_name = line.replace("[","").replace("]","").strip()
if line.find(":vars") != -1 or line.find(":children") != -1: if line.find(":vars") != -1 or line.find(":children") != -1:
active_group_name = active_group_name.rsplit(":", 1)[0] active_group_name = active_group_name.rsplit(":", 1)[0]
self.groups[active_group_name] = Group(name=active_group_name) if active_group_name not in self.groups:
self.groups[active_group_name] = Group(name=active_group_name)
active_group_name = None active_group_name = None
else: elif active_group_name not in self.groups:
new_group = self.groups[active_group_name] = Group(name=active_group_name) new_group = self.groups[active_group_name] = Group(name=active_group_name)
all.add_child_group(new_group) all.add_child_group(new_group)
elif line.startswith("#") or line == '': elif line.startswith("#") or line == '':

View file

@ -142,7 +142,7 @@ class TestInventory(unittest.TestCase):
print vars print vars
expected = dict( expected = dict(
a='1', b='2', c='3', d='100002', rga='1', rgb='2', rgc='3', a='1', b='2', c='3', d='10002', rga='1', rgb='2', rgc='3',
inventory_hostname='rtp_a', inventory_hostname_short='rtp_a', inventory_hostname='rtp_a', inventory_hostname_short='rtp_a',
group_names=[ 'eastcoast', 'nc', 'redundantgroup', 'redundantgroup2', 'redundantgroup3', 'rtp', 'us' ] group_names=[ 'eastcoast', 'nc', 'redundantgroup', 'redundantgroup2', 'redundantgroup3', 'rtp', 'us' ]
) )