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 358ec63a8fa..6ad7017db89 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( @@ -289,25 +313,7 @@ def main(): 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') diff --git a/test/integration/targets/aci_switch_leaf_selector/tasks/main.yml b/test/integration/targets/aci_switch_leaf_selector/tasks/main.yml index 95e81d27124..fccc77c9839 100644 --- a/test/integration/targets/aci_switch_leaf_selector/tasks/main.yml +++ b/test/integration/targets/aci_switch_leaf_selector/tasks/main.yml @@ -68,7 +68,7 @@ - sw_leaf_selec_check_mode_present is changed - sw_leaf_selec_present is changed - sw_leaf_selec_present.previous == [] - - 'sw_leaf_selec_present.sent == {"infraLeafS": {"attributes": {"name": "leaf_selector_name"}, "children": [{"infraNodeBlk": {"attributes": {"from_": "1011", "name": "node_blk_name", "to_": "1011"}}},{"infraRsAccNodePGrp": {"attributes": {"tDn": "uni/infra/funcprof/accnodepgrp-None"}}}]}}' + - 'sw_leaf_selec_present.sent == {"infraLeafS": {"attributes": {"name": "leaf_selector_name"}, "children": [{"infraNodeBlk": {"attributes": {"from_": "1011", "name": "node_blk_name", "to_": "1011"}}}]}}' - sw_leaf_selec_idempotent is not changed - sw_leaf_selec_idempotent.sent == {} - sw_leaf_selec_update is changed