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 ini handles children no matter the order

fixed 'pending declarations' assumption that children only have 1 parent
fixes #25488
This commit is contained in:
Brian Coca 2017-06-08 10:36:24 -04:00
parent a00089c341
commit 8badfcd7fe

View file

@ -200,7 +200,8 @@ class InventoryModule(BaseFileInventoryPlugin):
if groupname in pending_declarations and state != 'vars':
if pending_declarations[groupname]['state'] == 'children':
self.inventory.add_child(pending_declarations[groupname]['parent'], groupname)
for parent in pending_declarations[groupname]['parents']:
self.inventory.add_child(parent, groupname)
del pending_declarations[groupname]
continue
@ -231,7 +232,10 @@ class InventoryModule(BaseFileInventoryPlugin):
elif state == 'children':
child = self._parse_group_name(line)
if child not in self.inventory.groups:
pending_declarations[child] = dict(line=self.lineno, state=state, name=child, parent=groupname)
if child not in pending_declarations:
pending_declarations[child] = dict(line=self.lineno, state=state, name=child, parents=[groupname])
else:
pending_declarations[child]['parents'].append(groupname)
else:
self.inventory.add_child(groupname, child)
@ -249,7 +253,7 @@ class InventoryModule(BaseFileInventoryPlugin):
if decl['state'] == 'vars':
raise AnsibleError("%s:%d: Section [%s:vars] not valid for undefined group: %s" % (path, decl['line'], decl['name'], decl['name']))
elif decl['state'] == 'children':
raise AnsibleError("%s:%d: Section [%s:children] includes undefined group: %s" % (path, decl['line'], decl['parent'], decl['name']))
raise AnsibleError("%s:%d: Section [%s:children] includes undefined group: %s" % (path, decl['line'], decl['parents'].pop(), decl['name']))
def _parse_group_name(self, line):
'''