From b47dcf2edfaefb656c3e9fc33f99120eb49e086a Mon Sep 17 00:00:00 2001 From: mwiebe Date: Sat, 9 Aug 2025 15:16:33 -0400 Subject: [PATCH 1/3] Initial work on this issue --- plugins/modules/dcnm_vrf.py | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/plugins/modules/dcnm_vrf.py b/plugins/modules/dcnm_vrf.py index 3971cf10b..25ad50df0 100644 --- a/plugins/modules/dcnm_vrf.py +++ b/plugins/modules/dcnm_vrf.py @@ -578,7 +578,8 @@ from ansible_collections.cisco.dcnm.plugins.module_utils.network.dcnm.dcnm import ( dcnm_get_ip_addr_info, dcnm_get_url, dcnm_send, dcnm_version_supported, get_fabric_details, get_fabric_inventory_details, get_ip_sn_dict, - get_sn_fabric_dict, validate_list_of_dicts, search_nested_json) + get_sn_fabric_dict, validate_list_of_dicts, search_nested_json, + find_dict_in_list_by_key_value) from ..module_utils.common.log_v2 import Log @@ -1656,10 +1657,10 @@ def get_have(self): attach_list = vrf_attach["lanAttachList"] deploy_vrf = "" for attach in attach_list: - attach_state = not attach["lanAttachState"] == "NA" - deploy = attach["isLanAttached"] + attach_state = bool(attach.get("isLanAttached", False)) + deploy = attach_state deployed = False - if deploy and ( + if attach_state and ( attach["lanAttachState"] == "OUT-OF-SYNC" or attach["lanAttachState"] == "PENDING" ): @@ -2064,10 +2065,17 @@ def get_diff_replace(self): self.diff_deploy = diff_deploy return + modified_all_vrfs = copy.deepcopy(all_vrfs) + for vrf in all_vrfs: + # If the playbook sets the deploy key to False, then we need to remove the vrf from the deploy list. + want_vrf_data = find_dict_in_list_by_key_value(search=self.config, key="vrf_name", value=vrf) + if want_vrf_data['deploy'] is False: + modified_all_vrfs.remove(vrf) + if not self.diff_deploy: - diff_deploy.update({"vrfNames": ",".join(all_vrfs)}) + diff_deploy.update({"vrfNames": ",".join(modified_all_vrfs)}) else: - vrfs = self.diff_deploy["vrfNames"] + "," + ",".join(all_vrfs) + vrfs = self.diff_deploy["vrfNames"] + "," + ",".join(modified_all_vrfs) diff_deploy.update({"vrfNames": vrfs}) self.diff_attach = copy.deepcopy(diff_attach) @@ -2368,7 +2376,14 @@ def diff_merge_attach(self, replace=False): if deploy_vrf: all_vrfs.append(deploy_vrf) - if len(all_vrfs) != 0: + modified_all_vrfs = copy.deepcopy(all_vrfs) + for vrf in all_vrfs: + # If the playbook sets the deploy key to False, then we need to remove the vrf from the deploy list. + want_vrf_data = find_dict_in_list_by_key_value(search=self.config, key="vrf_name", value=vrf) + if want_vrf_data['deploy'] is False: + modified_all_vrfs.remove(vrf) + + if len(modified_all_vrfs) != 0: diff_deploy.update({"vrfNames": ",".join(all_vrfs)}) self.diff_attach = diff_attach From 071401404283b38e185418bd77afb14afef38ee7 Mon Sep 17 00:00:00 2001 From: Neil John <39439797+neiljohn-gh@users.noreply.github.com> Date: Tue, 12 Aug 2025 15:25:03 +0530 Subject: [PATCH 2/3] Updated dcnm_vrf to honor deploy flag --- plugins/modules/dcnm_vrf.py | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/plugins/modules/dcnm_vrf.py b/plugins/modules/dcnm_vrf.py index 25ad50df0..6c16cc8e6 100644 --- a/plugins/modules/dcnm_vrf.py +++ b/plugins/modules/dcnm_vrf.py @@ -2069,14 +2069,15 @@ def get_diff_replace(self): for vrf in all_vrfs: # If the playbook sets the deploy key to False, then we need to remove the vrf from the deploy list. want_vrf_data = find_dict_in_list_by_key_value(search=self.config, key="vrf_name", value=vrf) - if want_vrf_data['deploy'] is False: + if want_vrf_data.get('deploy',True) is False: modified_all_vrfs.remove(vrf) - if not self.diff_deploy: - diff_deploy.update({"vrfNames": ",".join(modified_all_vrfs)}) - else: - vrfs = self.diff_deploy["vrfNames"] + "," + ",".join(modified_all_vrfs) - diff_deploy.update({"vrfNames": vrfs}) + if modified_all_vrfs: + if not diff_deploy: + diff_deploy.update({"vrfNames": ",".join(modified_all_vrfs)}) + else: + vrfs = self.diff_deploy["vrfNames"] + "," + ",".join(modified_all_vrfs) + diff_deploy.update({"vrfNames": vrfs}) self.diff_attach = copy.deepcopy(diff_attach) self.diff_deploy = copy.deepcopy(diff_deploy) @@ -2380,11 +2381,15 @@ def diff_merge_attach(self, replace=False): for vrf in all_vrfs: # If the playbook sets the deploy key to False, then we need to remove the vrf from the deploy list. want_vrf_data = find_dict_in_list_by_key_value(search=self.config, key="vrf_name", value=vrf) - if want_vrf_data['deploy'] is False: + if want_vrf_data.get("deploy", True) is False: modified_all_vrfs.remove(vrf) - if len(modified_all_vrfs) != 0: - diff_deploy.update({"vrfNames": ",".join(all_vrfs)}) + if modified_all_vrfs: + if not diff_deploy: + diff_deploy.update({"vrfNames": ",".join(modified_all_vrfs)}) + else: + vrfs = self.diff_deploy["vrfNames"] + "," + ",".join(modified_all_vrfs) + diff_deploy.update({"vrfNames": vrfs}) self.diff_attach = diff_attach self.diff_deploy = diff_deploy From a3c90c44d85a63e20976e12cc61c4342020c33da Mon Sep 17 00:00:00 2001 From: Neil John <39439797+neiljohn-gh@users.noreply.github.com> Date: Tue, 12 Aug 2025 15:31:57 +0530 Subject: [PATCH 3/3] Fixed whitespace sanity issue --- plugins/modules/dcnm_vrf.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/modules/dcnm_vrf.py b/plugins/modules/dcnm_vrf.py index 6c16cc8e6..b5c28c6e5 100644 --- a/plugins/modules/dcnm_vrf.py +++ b/plugins/modules/dcnm_vrf.py @@ -2069,7 +2069,7 @@ def get_diff_replace(self): for vrf in all_vrfs: # If the playbook sets the deploy key to False, then we need to remove the vrf from the deploy list. want_vrf_data = find_dict_in_list_by_key_value(search=self.config, key="vrf_name", value=vrf) - if want_vrf_data.get('deploy',True) is False: + if want_vrf_data.get('deploy', True) is False: modified_all_vrfs.remove(vrf) if modified_all_vrfs: