diff --git a/changelogs/fragments/47668-aci_switch_leaf_selector-support_empty_policy_group.yaml b/changelogs/fragments/47668-aci_switch_leaf_selector-support_empty_policy_group.yaml new file mode 100644 index 00000000000..b9ff26f81b2 --- /dev/null +++ b/changelogs/fragments/47668-aci_switch_leaf_selector-support_empty_policy_group.yaml @@ -0,0 +1,2 @@ +bugfixes: +- aci_switch_leaf_selector - Support empty policy_group 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 c092334edb0..42e3286fe6f 100644 --- a/lib/ansible/modules/network/aci/aci_switch_leaf_selector.py +++ b/lib/ansible/modules/network/aci/aci_switch_leaf_selector.py @@ -283,31 +283,37 @@ 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( descr=description, name=leaf, ), - child_configs=[ - dict( - infraNodeBlk=dict( - attributes=dict( - descr=leaf_node_blk_description, - name=leaf_node_blk, - from_=from_, - to_=to_, - ), - ), - ), - dict( - infraRsAccNodePGrp=dict( - attributes=dict( - tDn='uni/infra/funcprof/accnodepgrp-{0}'.format(policy_group), - ), - ), - ), - ], + child_configs=child_configs, ) aci.get_diff(aci_class='infraLeafS')