From 8badfcd7feb8b333b8afa658dcea5de2a073e02d Mon Sep 17 00:00:00 2001 From: Brian Coca Date: Thu, 8 Jun 2017 10:36:24 -0400 Subject: [PATCH] make sure ini handles children no matter the order fixed 'pending declarations' assumption that children only have 1 parent fixes #25488 --- lib/ansible/plugins/inventory/ini.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/ansible/plugins/inventory/ini.py b/lib/ansible/plugins/inventory/ini.py index ed32aa0ec1..3a2a1d4e55 100644 --- a/lib/ansible/plugins/inventory/ini.py +++ b/lib/ansible/plugins/inventory/ini.py @@ -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): '''