diff --git a/lib/ansible/plugins/inventory/ini.py b/lib/ansible/plugins/inventory/ini.py index f35e352678..ee41ae4d95 100644 --- a/lib/ansible/plugins/inventory/ini.py +++ b/lib/ansible/plugins/inventory/ini.py @@ -180,7 +180,17 @@ class InventoryModule(BaseFileInventoryPlugin): # but [groupname:vars] is allowed only if the # group is declared elsewhere. # We add the group anyway, but make a note in pending_declarations to check at the end. if state == 'vars': - pending_declarations[groupname] = dict(line=self.lineno, state=state, name=groupname) + + # It's possible that a group is previously pending due to being + # defined as a child group, in that case we simply pass so that + # the logic below to process pending declarations will take the + # appropriate action for a pending child group instead of + # incorrectly handling it as a var state pending declaration + if groupname in pending_declarations: + if pending_declarations[groupname]['state'] == 'children': + pass + else: + pending_declarations[groupname] = dict(line=self.lineno, state=state, name=groupname) self.inventory.add_group(groupname)