|
584 | 584 | from ansible_collections.cisco.dcnm.plugins.module_utils.network.dcnm.dcnm import ( |
585 | 585 | dcnm_get_ip_addr_info, dcnm_get_url, dcnm_send, dcnm_version_supported, |
586 | 586 | get_fabric_details, get_fabric_inventory_details, get_ip_sn_dict, |
587 | | - get_sn_fabric_dict, validate_list_of_dicts, search_nested_json) |
| 587 | + get_sn_fabric_dict, validate_list_of_dicts, search_nested_json, |
| 588 | + find_dict_in_list_by_key_value) |
588 | 589 |
|
589 | 590 | from ..module_utils.common.log_v2 import Log |
590 | 591 |
|
@@ -1675,10 +1676,10 @@ def get_have(self): |
1675 | 1676 | attach_list = vrf_attach["lanAttachList"] |
1676 | 1677 | deploy_vrf = "" |
1677 | 1678 | for attach in attach_list: |
1678 | | - attach_state = not attach["lanAttachState"] == "NA" |
1679 | | - deploy = attach["isLanAttached"] |
| 1679 | + attach_state = bool(attach.get("isLanAttached", False)) |
| 1680 | + deploy = attach_state |
1680 | 1681 | deployed = False |
1681 | | - if deploy and ( |
| 1682 | + if attach_state and ( |
1682 | 1683 | attach["lanAttachState"] == "OUT-OF-SYNC" |
1683 | 1684 | or attach["lanAttachState"] == "PENDING" |
1684 | 1685 | ): |
@@ -2083,11 +2084,19 @@ def get_diff_replace(self): |
2083 | 2084 | self.diff_deploy = diff_deploy |
2084 | 2085 | return |
2085 | 2086 |
|
2086 | | - if not self.diff_deploy: |
2087 | | - diff_deploy.update({"vrfNames": ",".join(all_vrfs)}) |
2088 | | - else: |
2089 | | - vrfs = self.diff_deploy["vrfNames"] + "," + ",".join(all_vrfs) |
2090 | | - diff_deploy.update({"vrfNames": vrfs}) |
| 2087 | + modified_all_vrfs = copy.deepcopy(all_vrfs) |
| 2088 | + for vrf in all_vrfs: |
| 2089 | + # If the playbook sets the deploy key to False, then we need to remove the vrf from the deploy list. |
| 2090 | + want_vrf_data = find_dict_in_list_by_key_value(search=self.config, key="vrf_name", value=vrf) |
| 2091 | + if want_vrf_data.get('deploy', True) is False: |
| 2092 | + modified_all_vrfs.remove(vrf) |
| 2093 | + |
| 2094 | + if modified_all_vrfs: |
| 2095 | + if not diff_deploy: |
| 2096 | + diff_deploy.update({"vrfNames": ",".join(modified_all_vrfs)}) |
| 2097 | + else: |
| 2098 | + vrfs = self.diff_deploy["vrfNames"] + "," + ",".join(modified_all_vrfs) |
| 2099 | + diff_deploy.update({"vrfNames": vrfs}) |
2091 | 2100 |
|
2092 | 2101 | self.diff_attach = copy.deepcopy(diff_attach) |
2093 | 2102 | self.diff_deploy = copy.deepcopy(diff_deploy) |
@@ -2388,8 +2397,19 @@ def diff_merge_attach(self, replace=False): |
2388 | 2397 | if deploy_vrf: |
2389 | 2398 | all_vrfs.append(deploy_vrf) |
2390 | 2399 |
|
2391 | | - if len(all_vrfs) != 0: |
2392 | | - diff_deploy.update({"vrfNames": ",".join(all_vrfs)}) |
| 2400 | + modified_all_vrfs = copy.deepcopy(all_vrfs) |
| 2401 | + for vrf in all_vrfs: |
| 2402 | + # If the playbook sets the deploy key to False, then we need to remove the vrf from the deploy list. |
| 2403 | + want_vrf_data = find_dict_in_list_by_key_value(search=self.config, key="vrf_name", value=vrf) |
| 2404 | + if want_vrf_data.get("deploy", True) is False: |
| 2405 | + modified_all_vrfs.remove(vrf) |
| 2406 | + |
| 2407 | + if modified_all_vrfs: |
| 2408 | + if not diff_deploy: |
| 2409 | + diff_deploy.update({"vrfNames": ",".join(modified_all_vrfs)}) |
| 2410 | + else: |
| 2411 | + vrfs = self.diff_deploy["vrfNames"] + "," + ",".join(modified_all_vrfs) |
| 2412 | + diff_deploy.update({"vrfNames": vrfs}) |
2393 | 2413 |
|
2394 | 2414 | self.diff_attach = diff_attach |
2395 | 2415 | self.diff_deploy = diff_deploy |
|
0 commit comments