From 4df610f9611a02591de83d404cb83a424bb273fd Mon Sep 17 00:00:00 2001 From: Adam Miller Date: Mon, 11 Dec 2017 12:44:44 -0600 Subject: [PATCH] order agnostic child group definition in inventory Previously if a child's group vars section was defined before the child group itself, an edge case would be hit where the state of the pending declaration would process as var and therefore drop the child pending declaration context. This would result in the group vars defined for the parent group being out of scope for the child group. Example: [web:children] appnodes proxies [web:vars] deployment_type=prod [appnodes:vars] foo_var=true [appnodes] appnodes[1:3].example.com [proxies:vars] bar_var=true [proxies] proxies[1:3].example.com Previously the deployment_type variable would be out of scope for both the appnodes and proxies groups. This patch fixes that. Signed-off-by: Adam Miller --- lib/ansible/plugins/inventory/ini.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) 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)