diff --git a/lib/ansible/modules/network/aci/aci_switch_leaf_selector.py b/lib/ansible/modules/network/aci/aci_switch_leaf_selector.py index 42e3286fe6f..6544b7e9262 100644 --- a/lib/ansible/modules/network/aci/aci_switch_leaf_selector.py +++ b/lib/ansible/modules/network/aci/aci_switch_leaf_selector.py @@ -260,6 +260,30 @@ def main(): policy_group = module.params['policy_group'] state = module.params['state'] + # Build child_configs dynamically + child_configs = [ + dict( + infraNodeBlk=dict( + attributes=dict( + descr=leaf_node_blk_description, + name=leaf_node_blk, + from_=from_, + to_=to_, + ), + ), + ), + ] + + # Add infraRsAccNodePGrp only when policy_group was defined + if policy_group is not None: + child_configs.append(dict( + infraRsAccNodePGrp=dict( + attributes=dict( + tDn='uni/infra/funcprof/accnodepgrp-{0}'.format(policy_group), + ), + ), + )) + aci = ACIModule(module) aci.construct_url( root_class=dict( @@ -283,30 +307,6 @@ def main(): aci.get_existing() if state == 'present': - # Build child_configs dynamically - child_configs = [ - dict( - infraNodeBlk=dict( - attributes=dict( - descr=leaf_node_blk_description, - name=leaf_node_blk, - from_=from_, - to_=to_, - ), - ), - ), - ] - - # Add infraRsAccNodePGrp only when policy_group was defined - if policy_group is not None: - child_configs.append(dict( - infraRsAccNodePGrp=dict( - attributes=dict( - tDn='uni/infra/funcprof/accnodepgrp-{0}'.format(policy_group), - ), - ), - )) - aci.payload( aci_class='infraLeafS', class_config=dict(