From bb6d543dac9e145a84db1f2669b2e14820f819ce Mon Sep 17 00:00:00 2001 From: Matt Tarkington Date: Wed, 18 Sep 2024 05:12:18 -0400 Subject: [PATCH] Prepend fabric name (#189) * prepend fabric name * rearrange run_map tasks * update run_map action plugins & reorder valdiate tasks --- .gitignore | 1 + plugins/action/common/read_run_map.py | 5 ++- plugins/action/common/run_map.py | 5 ++- roles/validate/tasks/sub_main.yml | 46 ++++++++++++++------------- 4 files changed, 33 insertions(+), 24 deletions(-) diff --git a/.gitignore b/.gitignore index 74a59879..b8c76254 100644 --- a/.gitignore +++ b/.gitignore @@ -142,6 +142,7 @@ roles/dtc/deploy/files roles/dtc/remove/files roles/validate/files/schema.yaml roles/validate/files/run_map.yml +roles/validate/files/*_run_map.yml !roles/validate/files/rules/enhanced_rules !roles/validate/files/rules/enhanced_rules/.gitkeep !roles/validate/files/rules/required_rules/* diff --git a/plugins/action/common/read_run_map.py b/plugins/action/common/read_run_map.py index b4d5f097..9c6eac28 100644 --- a/plugins/action/common/read_run_map.py +++ b/plugins/action/common/read_run_map.py @@ -39,13 +39,16 @@ def run(self, tmp=None, task_vars=None): results = super(ActionModule, self).run(tmp, task_vars) results['diff_run'] = True + model_data = task_vars['model_data']['data'] + fabric_name = model_data["vxlan"]["global"]["name"] + if 'dtc' in task_vars['role_path']: common_role_path = os.path.dirname(task_vars['role_path']) common_role_path = os.path.dirname(common_role_path) + '/validate/files' else: common_role_path = os.path.dirname(task_vars['role_path']) + '/validate/files' - run_map_file_path = common_role_path + '/run_map.yml' + run_map_file_path = common_role_path + f'/{fabric_name}_run_map.yml' if not os.path.exists(run_map_file_path): # Return failure if run_map file does not exist diff --git a/plugins/action/common/run_map.py b/plugins/action/common/run_map.py index 50d1db8f..2784a0b9 100644 --- a/plugins/action/common/run_map.py +++ b/plugins/action/common/run_map.py @@ -41,7 +41,9 @@ def run(self, tmp=None, task_vars=None): results = super(ActionModule, self).run(tmp, task_vars) results['failed'] = False + model_data = task_vars['model_data']['data'] stage = self._task.args['stage'] + fabric_name = model_data["vxlan"]["global"]["name"] if 'dtc' in task_vars['role_path']: common_role_path = os.path.dirname(task_vars['role_path']) @@ -52,7 +54,8 @@ def run(self, tmp=None, task_vars=None): if not os.path.exists(common_role_path): # Return failure if the common role path does not exist results['failed'] = True - run_map_file_path = common_role_path + '/run_map.yml' + + run_map_file_path = common_role_path + f'/{fabric_name}_run_map.yml' if stage == 'starting_execution': updated_run_map = {} diff --git a/roles/validate/tasks/sub_main.yml b/roles/validate/tasks/sub_main.yml index b102c5e5..4f71669f 100644 --- a/roles/validate/tasks/sub_main.yml +++ b/roles/validate/tasks/sub_main.yml @@ -31,22 +31,6 @@ - ansible.builtin.debug: msg="Inventory Directory - {{ inventory_dir }}" -- name: Read Run Map From Previous Run - cisco.nac_dc_vxlan.common.read_run_map: - register: run_map_read_result - delegate_to: localhost - -- name: Debug Run Map Read Result - ansible.builtin.debug: - msg: "{{ run_map_read_result }}" - delegate_to: localhost - -- name: Initialize Run Map - cisco.nac_dc_vxlan.common.run_map: - stage: starting_execution - register: run_map - delegate_to: localhost - - name: Validate NDFC Service Model Data ansible.builtin.debug: msg="Calling Role Validate - nac_dc_vxlan.validate" @@ -56,6 +40,12 @@ - ansible.builtin.debug: msg="Workflow is Direct to Controller (DTC)" when: hostvars[inventory_hostname]['ansible_network_os'] == "cisco.dcnm.dcnm" +- name: Verify Connection to NDFC {{ ansible_host }} on Port {{ ansible_httpapi_port | default(443) }} + ansible.builtin.include_tasks: verify_ndfc_connectivity.yml + +- name: Verify Authorization to NDFC {{ ansible_host }} on Port {{ ansible_httpapi_port | default(443) }} + ansible.builtin.include_tasks: verify_ndfc_authorization.yml + - name: Check for Schema Path Being Defined ansible.builtin.set_fact: schema_path: '' @@ -89,12 +79,6 @@ when: enhanced_rules_path is defined and enhanced_rules_path delegate_to: localhost -- name: Verify Connection to NDFC {{ ansible_host }} on Port {{ ansible_httpapi_port | default(443) }} - ansible.builtin.include_tasks: verify_ndfc_connectivity.yml - -- name: Verify Authorization to NDFC {{ ansible_host }} on Port {{ ansible_httpapi_port | default(443) }} - ansible.builtin.include_tasks: verify_ndfc_authorization.yml - - name: Prepare Service Model cisco.nac_dc_vxlan.common.prepare_service_model: inventory_hostname: "{{ inventory_hostname }}" @@ -119,6 +103,24 @@ register: check_roles delegate_to: localhost +- name: Read Run Map From Previous Run + cisco.nac_dc_vxlan.common.read_run_map: + model_data: "{{ MD_Extended }}" + register: run_map_read_result + delegate_to: localhost + +- name: Debug Run Map Read Result + ansible.builtin.debug: + msg: "{{ run_map_read_result }}" + delegate_to: localhost + +- name: Initialize Run Map + cisco.nac_dc_vxlan.common.run_map: + model_data: "{{ MD_Extended }}" + stage: starting_execution + register: run_map + delegate_to: localhost + - name: Manage Previous Service Model Data Files ansible.builtin.include_tasks: manage_model_files_previous.yml when: check_roles['save_previous']