From 56059eb6e0e1800eb72709cce805d67147e610d8 Mon Sep 17 00:00:00 2001 From: Mike Wiebe Date: Fri, 8 Nov 2024 06:15:46 -0500 Subject: [PATCH] Fix tags (#225) * Fix tags * More tag refactoring * Rename connectivity tags * More tag refactoring --- plugins/action/common/check_roles.py | 2 +- roles/common_global/vars/main.yml | 62 +++++++++++++++++-- roles/dtc/common/meta/main.yml | 3 +- roles/dtc/common/tasks/main.yml | 2 +- roles/dtc/connectivity_check/tasks/main.yml | 22 +++---- .../tasks/verify_ndfc_authorization.yml | 2 - .../tasks/verify_ndfc_connectivity.yml | 2 - roles/dtc/create/meta/main.yml | 3 +- roles/dtc/deploy/meta/main.yml | 2 +- roles/dtc/deploy/tasks/main.yml | 2 +- roles/dtc/remove/meta/main.yml | 2 +- roles/validate/tasks/main.yml | 2 +- 12 files changed, 74 insertions(+), 32 deletions(-) diff --git a/plugins/action/common/check_roles.py b/plugins/action/common/check_roles.py index 64fb0a6d..3a5787cb 100644 --- a/plugins/action/common/check_roles.py +++ b/plugins/action/common/check_roles.py @@ -38,7 +38,7 @@ def run(self, tmp=None, task_vars=None): results['save_previous'] = False roles = self._task.args['role_list'] - for role in ['cisco.nac_dc_vxlan.create', 'cisco.nac_dc_vxlan.remove']: + for role in ['cisco.nac_dc_vxlan.create', 'cisco.nac_dc_vxlan.deploy', 'cisco.nac_dc_vxlan.remove']: if role in roles: results['save_previous'] = True diff --git a/roles/common_global/vars/main.yml b/roles/common_global/vars/main.yml index 32eedb1a..7821ee4d 100644 --- a/roles/common_global/vars/main.yml +++ b/roles/common_global/vars/main.yml @@ -24,8 +24,7 @@ nac_tags: # All Create and Remove Tags all: - - cc_connectivity_check - - cc_version + - cc_verify # ------------------------- - cr_manage_fabric - cr_manage_switches @@ -47,8 +46,59 @@ nac_tags: - role_remove # All Connectivity Check Tags connectivity_check: - - cc_connectivity_check - - cc_version + - cc_verify + - role_create + - role_deploy + - role_remove + - cr_manage_fabric + - cr_manage_switches + - cr_manage_vpc_peers + - cr_manage_interfaces + - cr_manage_vrfs_networks + - cr_manage_policy + - rr_manage_interfaces + - rr_manage_networks + - rr_manage_vrfs + - rr_manage_vpc_peers + - rr_manage_links + - rr_manage_switches + # We need the ability to pass tags to the common role but we don't need the following + # - validate, cc_verify + common_role: + - role_create + - role_deploy + - role_remove + - cr_manage_fabric + - cr_manage_switches + - cr_manage_vpc_peers + - cr_manage_interfaces + - cr_manage_vrfs_networks + - cr_manage_policy + - rr_manage_interfaces + - rr_manage_networks + - rr_manage_vrfs + - rr_manage_vpc_peers + - rr_manage_links + - rr_manage_switches + # We need the ability to pass tags to the validate role but we don't need the following + # - cc_verify + validate_role: + - role_validate + - role_create + - role_deploy + - role_remove + - cr_manage_fabric + - cr_manage_switches + - cr_manage_vpc_peers + - cr_manage_interfaces + - cr_manage_vrfs_networks + - cr_manage_policy + - rr_manage_interfaces + - rr_manage_networks + - rr_manage_vrfs + - rr_manage_vpc_peers + - rr_manage_links + - rr_manage_switches # All Create Tags create: - cr_manage_fabric @@ -89,5 +139,7 @@ nac_tags: - rr_manage_links remove_switches: - rr_manage_switches - + deploy: + - role_deploy + \ No newline at end of file diff --git a/roles/dtc/common/meta/main.yml b/roles/dtc/common/meta/main.yml index a307327f..1bba0904 100644 --- a/roles/dtc/common/meta/main.yml +++ b/roles/dtc/common/meta/main.yml @@ -25,4 +25,5 @@ galaxy_info: license: LICENSE min_ansible_version: 2.14.15 -dependencies: [cisco.nac_dc_vxlan.common_global] +dependencies: + - cisco.nac_dc_vxlan.common_global diff --git a/roles/dtc/common/tasks/main.yml b/roles/dtc/common/tasks/main.yml index 23badea6..7b71bf04 100644 --- a/roles/dtc/common/tasks/main.yml +++ b/roles/dtc/common/tasks/main.yml @@ -23,4 +23,4 @@ - name: Import Role Tasks ansible.builtin.import_tasks: sub_main.yml - tags: "{{ nac_tags.all }}" # Tags defined in roles/common_global/vars/main.yml + tags: "{{ nac_tags.common_role }}" # Tags defined in roles/common_global/vars/main.yml diff --git a/roles/dtc/connectivity_check/tasks/main.yml b/roles/dtc/connectivity_check/tasks/main.yml index 8e63667f..aa27fbdb 100644 --- a/roles/dtc/connectivity_check/tasks/main.yml +++ b/roles/dtc/connectivity_check/tasks/main.yml @@ -22,14 +22,12 @@ --- - name: Verify Connection to NDFC {{ ansible_host }} on Port {{ ansible_httpapi_port | default(443) }} - ansible.builtin.include_tasks: verify_ndfc_connectivity.yml - tags: - - cc_connectivity_check + ansible.builtin.import_tasks: verify_ndfc_connectivity.yml + tags: "{{ nac_tags.connectivity_check }}" # Tags defined in roles/common_global/vars/main.yml - name: Verify Authorization to NDFC {{ ansible_host }} on Port {{ ansible_httpapi_port | default(443) }} - ansible.builtin.include_tasks: verify_ndfc_authorization.yml - tags: - - cc_connectivity_check + ansible.builtin.import_tasks: verify_ndfc_authorization.yml + tags: "{{ nac_tags.connectivity_check }}" # Tags defined in roles/common_global/vars/main.yml - name: Get Cisco ND Version ansible.builtin.uri: @@ -41,25 +39,21 @@ timeout: 30 register: nd_version_response delegate_to: localhost - tags: - - cc_version + tags: "{{ nac_tags.connectivity_check }}" # Tags defined in roles/common_global/vars/main.yml - name: Set Cisco ND Version Var ansible.builtin.set_fact: nd_version: "{{ nd_version_response.json.major }}.{{ nd_version_response.json.minor }}.{{ nd_version_response.json.maintenance }}{{ nd_version_response.json.patch }}" - tags: - - cc_version + tags: "{{ nac_tags.connectivity_check }}" # Tags defined in roles/common_global/vars/main.yml - name: Get Cisco NDFC Version cisco.dcnm.dcnm_rest: method: GET path: /appcenter/cisco/ndfc/api/about/version register: ndfc_version - tags: - - cc_version + tags: "{{ nac_tags.connectivity_check }}" # Tags defined in roles/common_global/vars/main.yml - name: Set Cisco NDFC Version Var ansible.builtin.set_fact: ndfc_version: "{{ ndfc_version.response.DATA.version }}" - tags: - - cc_version + tags: "{{ nac_tags.connectivity_check }}" # Tags defined in roles/common_global/vars/main.yml diff --git a/roles/dtc/connectivity_check/tasks/verify_ndfc_authorization.yml b/roles/dtc/connectivity_check/tasks/verify_ndfc_authorization.yml index 596be075..6455bf6f 100644 --- a/roles/dtc/connectivity_check/tasks/verify_ndfc_authorization.yml +++ b/roles/dtc/connectivity_check/tasks/verify_ndfc_authorization.yml @@ -20,8 +20,6 @@ register: response # no_log: true delegate_to: localhost - tags: - - cc_connectivity_check rescue: - name: Fail Play If NDFC Authorization Test Failed diff --git a/roles/dtc/connectivity_check/tasks/verify_ndfc_connectivity.yml b/roles/dtc/connectivity_check/tasks/verify_ndfc_connectivity.yml index 3eb6bc3d..647a448b 100644 --- a/roles/dtc/connectivity_check/tasks/verify_ndfc_connectivity.yml +++ b/roles/dtc/connectivity_check/tasks/verify_ndfc_connectivity.yml @@ -11,5 +11,3 @@ state: started msg: Timed out waiting to connect to NDFC at https://{{ ansible_host }}:{{ ansible_httpapi_port | default(443) }}. Check the NDFC is reachable from the Ansible Controller. delegate_to: localhost - tags: - - cc_connectivity_check diff --git a/roles/dtc/create/meta/main.yml b/roles/dtc/create/meta/main.yml index 6315c4aa..7ae7026f 100644 --- a/roles/dtc/create/meta/main.yml +++ b/roles/dtc/create/meta/main.yml @@ -26,7 +26,6 @@ galaxy_info: min_ansible_version: 2.14.15 dependencies: - - cisco.nac_dc_vxlan.validate - - cisco.nac_dc_vxlan.common_global - cisco.nac_dc_vxlan.dtc.connectivity_check + - cisco.nac_dc_vxlan.validate - cisco.nac_dc_vxlan.dtc.common diff --git a/roles/dtc/deploy/meta/main.yml b/roles/dtc/deploy/meta/main.yml index a8d23bea..00f9ae86 100644 --- a/roles/dtc/deploy/meta/main.yml +++ b/roles/dtc/deploy/meta/main.yml @@ -26,6 +26,6 @@ galaxy_info: min_ansible_version: 2.14.15 dependencies: + - cisco.nac_dc_vxlan.dtc.connectivity_check - cisco.nac_dc_vxlan.validate - - cisco.nac_dc_vxlan.common_global - cisco.nac_dc_vxlan.dtc.common diff --git a/roles/dtc/deploy/tasks/main.yml b/roles/dtc/deploy/tasks/main.yml index e2d2d2be..96c5ec4c 100644 --- a/roles/dtc/deploy/tasks/main.yml +++ b/roles/dtc/deploy/tasks/main.yml @@ -23,7 +23,7 @@ - name: Import Role Tasks ansible.builtin.import_tasks: sub_main.yml - tags: "{{ nac_tags.create }}" # Tags defined in roles/common_global/vars/main.yml + tags: "{{ nac_tags.deploy }}" # Tags defined in roles/common_global/vars/main.yml when: changes_detected_fabric or changes_detected_inventory or changes_detected_vpc_peering or changes_detected_interfaces or changes_detected_link_vpc_peering or changes_detected_vrfs or changes_detected_networks or changes_detected_policy - name: Mark Stage Role Deploy Completed diff --git a/roles/dtc/remove/meta/main.yml b/roles/dtc/remove/meta/main.yml index 02d7de21..eb76fa87 100644 --- a/roles/dtc/remove/meta/main.yml +++ b/roles/dtc/remove/meta/main.yml @@ -26,6 +26,6 @@ galaxy_info: min_ansible_version: 2.14.15 dependencies: + - cisco.nac_dc_vxlan.dtc.connectivity_check - cisco.nac_dc_vxlan.validate - - cisco.nac_dc_vxlan.common_global - cisco.nac_dc_vxlan.dtc.common diff --git a/roles/validate/tasks/main.yml b/roles/validate/tasks/main.yml index e9b3eb7f..9d6e722c 100644 --- a/roles/validate/tasks/main.yml +++ b/roles/validate/tasks/main.yml @@ -24,7 +24,7 @@ - name: Import Role Tasks ansible.builtin.import_tasks: sub_main.yml - tags: "{{ nac_tags.all }}" # Tags defined in roles/common_global/vars/main.yml + tags: "{{ nac_tags.validate_role }}" # Tags defined in roles/common_global/vars/main.yml # Problems with lower versions of python and ansible # Python 3.9.16 and Ansible 7.3.0 (Ansible-Core 2.14.4) # Could ignore errors and try again with tags specified as below as a work around ...