diff --git a/README.md b/README.md index 766877c5..692c9d7e 100644 --- a/README.md +++ b/README.md @@ -2,15 +2,15 @@ [![Actions Status](https://github.com/netascode/ansible-dc-vxlan/workflows/CI/badge.svg)](https://github.com/netascode/ansible-dc-vxlan/actions) -Ansible collection for configuring Cisco VXLAN/EVPN fabric using Cisco Nexus Dashboard Fabric Controller (NDFC). Utilizing a foundation of a data model, this collection simplifies the configuration of VXLAN fabrics by abstracting the automation and utilizing a data model that represents the desired state of the fabric. An operator utilizing this collection will only have to modify the configuration state in the data model instead of creating the modules and the associated parameters. +Ansible Collection for configuring Cisco VXLAN EVPN fabrics using the Cisco Nexus Dashboard Fabric Controller (NDFC). This collection simplifies the configuration of VXLAN fabrics by abstracting the automation using a data model that represents the desired state of the fabric. With this collection, an operator only needs to modify the configuration state in the data model instead of creating custom playbooks with modules and the associated parameters. -This approach allows for a more consistent and repeatable configuration of VXLAN fabrics and is aligned with the methodology of infrastructure as code, where the configuration of NDFC would be saved in a version control system and managed as code. +This approach allows for consistent and repeatable configuration of VXLAN fabrics and aligns with Infrastructure as Code (IaC) methodology, where the configuration state of NDFC is saved in a version control system and managed as code. -Infrastructure as code (IaC) is a DevOps methodology that uses code to manage and provision IT infrastructure, instead of manual procedures. IaC uses a descriptive coding language to automate provisioning servers, operating systems, network devices and more. The NetAsCode VXLAN EVPN collection allows you to configure, in easy-to-understand YAML, data structures with the intended configuration state of a VXLAN fabric using Cisco Nexus Dashboard Fabric Controller. +Infrastructure as code (IaC) is a DevOps methodology that uses code to manage and provision IT infrastructure, bypassing manual procedures. IaC uses a descriptive coding language to automate the provisioning of servers, operating systems, network devices and more. -The NetAsCode VXLAN collection provides the capability to create a declarative method of configuration of VXLAN for [Cisco Nexus](https://www.cisco.com/site/us/en/products/networking/cloud-networking-switches/index.html) datacenter solution utilizing [Cisco Nexus Dashboard](https://www.cisco.com/site/us/en/products/networking/cloud-networking/nexus-platform/index.html). This allows the separation of data from execution logic. With little to no knowledge about automation, you can instantiate a VXLAN EVPN fabric with this collection. +The NetAsCode VXLAN EVPN collection allows you to configure, in easy-to-understand YAML, data structures describing the configuration state of a VXLAN fabric for [Cisco Nexus](https://www.cisco.com/site/us/en/products/networking/cloud-networking-switches/index.html) datacenters and then deploys this state using Ansible and the [Cisco Nexus Dashboard](https://www.cisco.com/site/us/en/products/networking/cloud-networking/nexus-platform/index.html). With little to no knowledge about automation, you can use this collection to instantiate a VXLAN EVPN fabric. -This is achieved by creating YAML files that contain a pre-determined data schema that is translated into underlying Ansible modules and resources. The core Ansible collection is open source and available. The collection is designed to be used in a CI/CD pipeline, which allows you to establish a declarative method of configuration of VXLAN for Cisco Nexus datacenter solution. +YAML files are created that contain a pre-determined data schema which is translated into underlying Ansible modules and resources. The core Ansible Collection is open source and available. This collection is designed to be used in a CI/CD pipeline in order to drive this declarative method of configuring a VXLAN fabric. > **Note**: For complete support and additional capabilities, Cisco provides a professional services capability under the Services as Code portfolio of services which can provide feature creation, end to end support and more. @@ -57,19 +57,17 @@ vpc_peering_delete_mode: false ### Advantages of the Roles in the Workflow -The primary advantage of the workflow is that you can insert these in different stages of the data model preparation and changes without having to worry about impacts to the network. In a SCM repository environment, pipelines can be configured to run the validate role before approvals in pull requests. - -The roles are designed to be idempotent and only make changes when there are changes in the data model. For different stages of changes in the network, you can comment out the roles that are not required to be executed. You can leave the final full execution potentially to only happen from a pipeline, yet allow for operators to validate changes before they are executed. +These roles when run in sequence (validate, create, deploy, remove) are designed to build out the entire fabric and can be executed by a pipeline. The roles can also be run in isolation by simply commenting out the roles that are not required during testing and fabric buildout to validate incremental changes. ## Quick Start Guide ### Set Environment for the Collection -The first procedure for execution of the collection is going to be the installation of a virtual environment to be able to install the collection and it's requirements. Recommendation is to utilize [pyenv](https://github.com/pyenv/pyenv) which provides a robust python virtual environment capability that also includes management of python versions. These instructions will be detailed around pyenv. For the pipeline execution please refer to *pipeline section* where it is documented at container level. +Installation of a Python virtual environment is needed in order to install the collection and it's requirements. We recommend [pyenv](https://github.com/pyenv/pyenv) which provides a robust Python virtual environment capability that also allows for management of different Python versions. The following instructions are detailed around using pyenv. For pipeline execution please refer to the pipeline section which is documented at container level. #### Step 1 - Installing the Example Repository -To simplify the usage of the collection we are providing you with an [example repository](https://github.com/netascode/ansible-dc-vxlan-example) that you can clone from GitHub which creates the proper skeleton required, including examples for pipelines. To clone the repository requires the installation of [git client](https://git-scm.com/downloads) that is available for all platforms. +To simplify getting started with this collection we provide you with an [example repository](https://github.com/netascode/ansible-dc-vxlan-example). Simply clone this repo from GitHub to create the required skeleton, including examples for pipelines. Cloaning the repository requires the installation of [git client](https://git-scm.com/downloads) which is available for all platforms. Run the following command in the location of interest. @@ -77,11 +75,12 @@ Run the following command in the location of interest. git clone https://github.com/netascode/ansible-dc-vxlan-example.git nac-vxlan ``` -This will clone the example repository into the directory nac-vxlan. Then you will delete the `.git` repository to remove the connection to the example repository. Which then allows you to create your own repository from this built structure. +This will clone the example repository into the directory `nac-vxlan`. Next delete the `.git` repository to remove the connection to the example repository. Now you can create your own repository from this pre-built structure. #### Step 2 - Create the Virtual Environment with pyenv -In this directory you will now create the new virtual environment. For pyenv to work you must install a version of Python that you want to utilize. At the _time of this writing_, a common version utilized is python version 3.10.13 so to install this with pyenv would be the command `pyenv install 3.10.13`. For detailed instructions please visit the [pyenv](https://github.com/pyenv/pyenv) site. +In this directory create a new virtual environment and install a Python version of your choice. At the time of this writting, a commonly used version is Python version 3.10.13. Command pyenv install 3.10.13 will install this version. For detailed instructions please visit the [pyenv](https://github.com/pyenv/pyenv) site. + ```bash cd nac-vxlan @@ -89,7 +88,7 @@ pyenv virtualenv nac-ndfc pyenv local nac-ndfc ``` -The final command is `pyenv local` which sets the environment so that whenever you enter the directory it will change into the right virtual environment. +Executing command pyenv local nac-ndfc sets the environment so that whenever the directory is entered it will change into the right virtual environment. #### Step 3 - Install Ansible and Additional Required Tools @@ -116,9 +115,9 @@ If you wish to install the galaxy collection inside the repository you are creat ansible-galaxy collection install -p collections/ansible_collections/ -r requirements.yaml ``` -You will need to then configure your ansible.cfg file to point to the correct location of the collection. +The `ansible.cfg` file needs to be configured to point to the location of the collection. -This is the path for all the python modules and libraries of the virtual environment that were created. If you look in that directory, you will find the collections package locations. Here is the base ansible.cfg, you will need to adjust the collection_path to your environment paths: +This is the path for all the python modules and libraries of the virtual environment that were created. If you look in that directory, you will find the collections package locations. Here is the base ansible.cfg, you will need to adjust the collections_path to your environment paths: ```bash [defaults] @@ -254,7 +253,7 @@ PEP440 is the schema used to describe the versions of Ansible. ## Building the Primary Playbook -The playbook for the NDFC as Code collection is the execution point of the this automation collection. In difference to other automation with collections, what is in this playbook is mostly static and not going to change. What is executed during automation is based on changes in the data model. Hence as changes happen in the data model, the playbook will call the modules and based on what has changed in the data model, is what is going to execute. +The following playbook for the NDFC as Code collection is the central execution point for this collection. Compared to automation in other collections, this playbook is designed to be mostly static and typically will not change. What gets executed during automation is based entirely on changes in the data model. When changes are made in the data model, the playbook will call the various roles and underlying modules to process the changes and update the NDFC managed fabric. The playbook is located in the root of the repository and is called `vxlan.yaml`. It contains the following: @@ -269,27 +268,51 @@ The playbook is located in the root of the repository and is called `vxlan.yaml` roles: # Prepare service model for all subsequent roles # - # - role: cisco.nac_dc_vxlan.validate + - role: cisco.nac_dc_vxlan.validate + tags: 'role_validate' # ----------------------- # DataCenter Roles # Role: cisco.netascode_dc_vxlan.dtc manages direct to controller NDFC workflows # - role: cisco.nac_dc_vxlan.dtc.create + tags: 'role_create' + - role: cisco.nac_dc_vxlan.dtc.deploy + tags: 'role_deploy' + - role: cisco.nac_dc_vxlan.dtc.remove + tags: 'role_remove' ``` -The `host` is defined as nac-ndfc1 which references back to the inventory file. The `roles` section is where the collection is going to be called. +The `host` is defined as nac-ndfc1 which references back to the `inventory.yaml` file. The `roles` section is where the various collection roles are called. + +The first role is `cisco.nac_dc_vxlan.validate` which is going to validate the data model. This is a required step to ensure that the data model is correct and that the data model is going to be able to be processed by the subsequent roles. + +The subsequent roles are the `cisco.nac_dc_vxlan.dtc.create`, `cisco.nac_dc_vxlan.dtc.deploy`, and `cisco.nac_dc_vxlan.dtc.remove` roles. These roles are the primary roles that will invoke changes in NDFC as described earlier. -The first role is `cisco.nac_dc_vxlan.validate` which is going to validate the data model. This is a required step to ensure that the data model is correct and that the data model is going to be able to be processed by the subsequent roles. **This role is going to execute by default even if not defined as it is required for the subsequent roles to execute.** In this example we are commenting out the role to show that it is not required to be defined in the playbook, but if you want to define a playbook that just runs the validation, you would uncomment this role. -The next roles are the `cisco.nac_dc_vxlan.dtc.create`, `cisco.nac_dc_vxlan.dtc.deploy`, and `cisco.nac_dc_vxlan.dtc.remove`. These roles are the primary roles that will invoke change in NDFC. The `create` role will create all the templates and variable parameters. The `deploy` role will deploy those changes to the NDFC controller. The `remove` role would remove the data model from the devices in the inventory. +> **Note**: For your safety as indicated ealier, the `remove` role also requires setting some variables to `true` under the `group_vars` directory. This is to avoid accidental removal of configuration from NDFC that might impact the network. This will be covered in more detail below. -> **Note**: For your safety, the `remove` role also requires settings some variables to true under the `group_vars` directory. This is done to avoid accidental removal of configuration from NDFC that might impact the network. This will be covered in a section below. +The playbook can be configured to execute only the roles that are required. For example, as you are building your data model and familiarizing yourself with the collection, you may comment out the `deploy` and `remove` roles and only execute the `validate` and `create` roles. This provides a quick way to make sure that the data model is structured correctly. +------ +**Role Level Tags:** -Since each of these roles are separate, you may configure the playbook to only execute the roles that are required. For example, as you are building your data model and getting to know the collection, you may comment out the `deploy` and `remove` roles to only execute the `validate` and `create` role. This provides a quick way to make sure that the data model is structured correctly. +To speed up execution when only certain roles need to be run the following role level tags are provided: + + * role_validate - Select and run `cisco.nac_dc_vxlan.validate` role + * role_create - Select and run `cisco.nac_dc_vxlan.create` role + * role_deploy - Select and run `cisco.nac_dc_vxlan.deploy` role + * role_remove - Select and run `cisco.nac_dc_vxlan.remove` role + +The validate role will automatically run if tags `role_create, role_deploy, role_remove` are specified. + +Example: Selectively Run `cisco.nac_dc_vxlan.create` role alone + +```bash +ansible-playbook -i inventory.yml vxlan.yml --tags role_create +``` ### See Also diff --git a/plugins/action/dtc/verify_tags.py b/plugins/action/dtc/verify_tags.py new file mode 100644 index 00000000..543b63ce --- /dev/null +++ b/plugins/action/dtc/verify_tags.py @@ -0,0 +1,52 @@ +# Copyright (c) 2024 Cisco Systems, Inc. and its affiliates +# +# Permission is hereby granted, free of charge, to any person obtaining a copy of +# this software and associated documentation files (the "Software"), to deal in +# the Software without restriction, including without limitation the rights to +# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +# the Software, and to permit persons to whom the Software is furnished to do so, +# subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +# +# SPDX-License-Identifier: MIT + +from __future__ import absolute_import, division, print_function + + +__metaclass__ = type + +from ansible.utils.display import Display +from ansible.plugins.action import ActionBase + +display = Display() + + +class ActionModule(ActionBase): + + def run(self, tmp=None, task_vars=None): + # self._supports_async = True + results = super(ActionModule, self).run(tmp, task_vars) + results['failed'] = False + + all_tags = self._task.args['all_tags'] + play_tags = self._task.args['play_tags'] + + if 'all' in play_tags: + return results + + for tag in play_tags: + if tag not in all_tags: + results['failed'] = True + results['msg'] = "Tag '{0}' not found in list of supported tags".format(tag) + results['supported_tags'] = all_tags + + return results diff --git a/roles/common_global/tasks/main.yml b/roles/common_global/tasks/main.yml new file mode 100644 index 00000000..f0ed1f7e --- /dev/null +++ b/roles/common_global/tasks/main.yml @@ -0,0 +1,27 @@ +# Copyright (c) 2024 Cisco Systems, Inc. and its affiliates +# +# Permission is hereby granted, free of charge, to any person obtaining a copy of +# this software and associated documentation files (the "Software"), to deal in +# the Software without restriction, including without limitation the rights to +# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +# the Software, and to permit persons to whom the Software is furnished to do so, +# subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +# +# SPDX-License-Identifier: MIT +--- + +- name: Verify User Tags + cisco.nac_dc_vxlan.dtc.verify_tags: + all_tags: "{{ nac_tags.all }}" + play_tags: "{{ ansible_run_tags }}" + tags: "{{ ansible_run_tags }}" \ No newline at end of file diff --git a/roles/common_global/vars/main.yml b/roles/common_global/vars/main.yml new file mode 100644 index 00000000..825d9955 --- /dev/null +++ b/roles/common_global/vars/main.yml @@ -0,0 +1,82 @@ +# Copyright (c) 2024 Cisco Systems, Inc. and its affiliates +# +# Permission is hereby granted, free of charge, to any person obtaining a copy of +# this software and associated documentation files (the "Software"), to deal in +# the Software without restriction, including without limitation the rights to +# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +# the Software, and to permit persons to whom the Software is furnished to do so, +# subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +# +# SPDX-License-Identifier: MIT + +--- + +nac_tags: + # All Create and Remove Tags + all: + - cr_manage_fabric + - cr_manage_switches + - cr_manage_vpc_peers + - cr_manage_interfaces + - cr_manage_vrfs_networks + # ------------------------- + - rr_manage_interfaces + - rr_manage_networks + - rr_manage_vrfs + - rr_manage_vpc_peers + - rr_manage_links + - rr_manage_switches + # ------------------------- + - role_validate + - role_create + - role_deploy + - role_remove + # All Create Tags + create: + - cr_manage_fabric + - cr_manage_switches + - cr_manage_vpc_peers + - cr_manage_interfaces + - cr_manage_vrfs_networks + create_fabric: + - cr_manage_fabric + create_switches: + - cr_manage_switches + create_vpc_peers: + - cr_manage_vpc_peers + create_interfaces: + - cr_manage_interfaces + create_vrfs_networks: + - cr_manage_vrfs_networks + # All Remove Tags + remove: + - rr_manage_interfaces + - rr_manage_networks + - rr_manage_vrfs + - rr_manage_vpc_peers + - rr_manage_links + - rr_manage_switches + remove_interfaces: + - rr_manage_interfaces + remove_networks: + - rr_manage_networks + remove_vrfs: + - rr_manage_vrfs + remove_vpc_peers: + - rr_manage_vpc_peers + remove_links: + - rr_manage_links + remove_switches: + - rr_manage_switches + + \ No newline at end of file diff --git a/roles/dtc/common/meta/main.yml b/roles/dtc/common/meta/main.yml index b2d888f8..a307327f 100644 --- a/roles/dtc/common/meta/main.yml +++ b/roles/dtc/common/meta/main.yml @@ -23,4 +23,6 @@ galaxy_info: author: Cisco description: Common infrastructure role dependency used by other roles in this collection license: LICENSE - min_ansible_version: 2.14.15 \ No newline at end of file + min_ansible_version: 2.14.15 + +dependencies: [cisco.nac_dc_vxlan.common_global] diff --git a/roles/dtc/common/tasks/main.yml b/roles/dtc/common/tasks/main.yml index f4e45bbd..23badea6 100644 --- a/roles/dtc/common/tasks/main.yml +++ b/roles/dtc/common/tasks/main.yml @@ -21,140 +21,6 @@ --- -- ansible.builtin.fail: msg="Service Model Not Defined. Role cisco.nac_dc_vxlan.validate Must Be Called First" - when: MD is undefined - delegate_to: localhost - -# -------------------------------------------------------------------- -# Remove all files from the previous run -# -------------------------------------------------------------------- -- name: Delete content & directory - ansible.builtin.file: - state: absent - path: "{{ role_path }}/files/" - delegate_to: localhost - -- name: Recreate the directory - ansible.builtin.file: - path: "{{ role_path }}/files/" - state: directory - mode: '0755' - delegate_to: localhost - -- name: Add gitkeep file back to the directory - ansible.builtin.file: - path: "{{ role_path }}/files/.gitkeep" - state: touch - delegate_to: localhost - -# -------------------------------------------------------------------- -# Build Create Fabric parameter List From Template -# -------------------------------------------------------------------- - -- name: Build Fabric Create Parameters - ansible.builtin.include_tasks: ndfc_fabric.yml - -# -------------------------------------------------------------------- -# Build NDFC Fabric Switch Inventory List From Template -# -------------------------------------------------------------------- - -- name: Build NDFC Fabric Switch Inventory List From Template - ansible.builtin.include_tasks: ndfc_inventory.yml - -# -------------------------------------------------------------------- -# Build Fabric intra links for vpc peering From Template -# -------------------------------------------------------------------- - -- name: Build Intra Fabric Links From Template - ansible.builtin.include_tasks: ndfc_link_vpc_peering.yml - -# -------------------------------------------------------------------- -# Build vPC Peering parameter List From Template -# -------------------------------------------------------------------- - -- name: Build vPC Peering Parameters - ansible.builtin.include_tasks: ndfc_vpc_peering.yml - -# -------------------------------------------------------------------- -# Build NDFC Fabric VRFs Attach List From Template -# -------------------------------------------------------------------- - -- name: Build NDFC Fabric VRFs Attach List From Template - ansible.builtin.include_tasks: ndfc_vrfs.yml - -# -------------------------------------------------------------------- -# Build NDFC Fabric Networks Attach List From Template -# -------------------------------------------------------------------- - -- name: Build NDFC Fabric Networks Attach List From Template - ansible.builtin.include_tasks: ndfc_networks.yml - -# -------------------------------------------------------------------- -# Build NDFC Fabric Loopback Interfaces List From Template -# -------------------------------------------------------------------- - -- name: Build NDFC Fabric Loopback Interfaces List From Template - ansible.builtin.include_tasks: ndfc_interface_loopback.yml - -# -------------------------------------------------------------------- -# Build NDFC Fabric Access Port-Channel Interfaces List From Template -# -------------------------------------------------------------------- - -- name: Build NDFC Fabric Access Port-Channel Interfaces List From Template - ansible.builtin.include_tasks: ndfc_interface_access_po.yml - -# -------------------------------------------------------------------- -# Build NDFC Fabric Trunk Port-Channel Interfaces List From Template -# -------------------------------------------------------------------- - -- name: Build NDFC Fabric Trunk Port-Channel Interfaces List From Template - ansible.builtin.include_tasks: ndfc_interface_trunk_po.yml - -# -------------------------------------------------------------------- -# Build NDFC Fabric Interface Routed List From Template -# -------------------------------------------------------------------- - -- name: Build NDFC Fabric Interface Routed List From Template - ansible.builtin.include_tasks: ndfc_interface_routed.yml - -# -------------------------------------------------------------------- -# Build NDFC Fabric Sub-Interface Routed List From Template -# -------------------------------------------------------------------- - -- name: Build NDFC Fabric Sub-Interface Routed List From Template - ansible.builtin.include_tasks: ndfc_sub_interface_routed.yml - -# -------------------------------------------------------------------- -# Build NDFC Fabric Routed Port-Channel Interface List From Template -# -------------------------------------------------------------------- - -- name: Build NDFC Fabric Routed Port-Channel Interface List From Template - ansible.builtin.include_tasks: ndfc_interface_po_routed.yml - -# -------------------------------------------------------------------- -# Build Trunk Interfaces List From Template -# -------------------------------------------------------------------- - -- name: Build Trunk Interfaces List From Template - ansible.builtin.include_tasks: ndfc_interface_trunk.yml - -# -------------------------------------------------------------------- -# Build Access Interfaces List From Template -# -------------------------------------------------------------------- - -- name: Build Access Interfaces List From Template - ansible.builtin.include_tasks: ndfc_interface_access.yml - -# -------------------------------------------------------------------- -# Build Fabric interface VPC List From Template -# -------------------------------------------------------------------- - -- name: Build Fabric interface VPC List From Template - ansible.builtin.include_tasks: ndfc_interface_vpc.yml - -# -------------------------------------------------------------------- -# Build Fabric interface all List From Template -# -------------------------------------------------------------------- - -- name: Build Fabric interface All List From Template - ansible.builtin.include_tasks: ndfc_interface_all.yml +- name: Import Role Tasks + ansible.builtin.import_tasks: sub_main.yml + tags: "{{ nac_tags.all }}" # Tags defined in roles/common_global/vars/main.yml diff --git a/roles/dtc/common/tasks/sub_main.yml b/roles/dtc/common/tasks/sub_main.yml new file mode 100644 index 00000000..0e7bd601 --- /dev/null +++ b/roles/dtc/common/tasks/sub_main.yml @@ -0,0 +1,160 @@ +# Copyright (c) 2024 Cisco Systems, Inc. and its affiliates +# +# Permission is hereby granted, free of charge, to any person obtaining a copy of +# this software and associated documentation files (the "Software"), to deal in +# the Software without restriction, including without limitation the rights to +# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +# the Software, and to permit persons to whom the Software is furnished to do so, +# subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +# +# SPDX-License-Identifier: MIT + +--- + +- ansible.builtin.fail: msg="Service Model Not Defined. Role cisco.nac_dc_vxlan.validate Must Be Called First" + when: MD is undefined + delegate_to: localhost + +# -------------------------------------------------------------------- +# Remove all files from the previous run +# -------------------------------------------------------------------- +- name: Delete content & directory + ansible.builtin.file: + state: absent + path: "{{ role_path }}/files/" + delegate_to: localhost + +- name: Recreate the directory + ansible.builtin.file: + path: "{{ role_path }}/files/" + state: directory + mode: '0755' + delegate_to: localhost + +- name: Add gitkeep file back to the directory + ansible.builtin.file: + path: "{{ role_path }}/files/.gitkeep" + state: touch + delegate_to: localhost + +# -------------------------------------------------------------------- +# Build Create Fabric parameter List From Template +# -------------------------------------------------------------------- + +- name: Build Fabric Create Parameters + ansible.builtin.include_tasks: ndfc_fabric.yml + +# -------------------------------------------------------------------- +# Build NDFC Fabric Switch Inventory List From Template +# -------------------------------------------------------------------- + +- name: Build NDFC Fabric Switch Inventory List From Template + ansible.builtin.include_tasks: ndfc_inventory.yml + +# -------------------------------------------------------------------- +# Build Fabric intra links for vpc peering From Template +# -------------------------------------------------------------------- + +- name: Build Intra Fabric Links From Template + ansible.builtin.include_tasks: ndfc_link_vpc_peering.yml + +# -------------------------------------------------------------------- +# Build vPC Peering parameter List From Template +# -------------------------------------------------------------------- + +- name: Build vPC Peering Parameters + ansible.builtin.include_tasks: ndfc_vpc_peering.yml + +# -------------------------------------------------------------------- +# Build NDFC Fabric VRFs Attach List From Template +# -------------------------------------------------------------------- + +- name: Build NDFC Fabric VRFs Attach List From Template + ansible.builtin.include_tasks: ndfc_vrfs.yml + +# -------------------------------------------------------------------- +# Build NDFC Fabric Networks Attach List From Template +# -------------------------------------------------------------------- + +- name: Build NDFC Fabric Networks Attach List From Template + ansible.builtin.include_tasks: ndfc_networks.yml + +# -------------------------------------------------------------------- +# Build NDFC Fabric Loopback Interfaces List From Template +# -------------------------------------------------------------------- + +- name: Build NDFC Fabric Loopback Interfaces List From Template + ansible.builtin.include_tasks: ndfc_interface_loopback.yml + +# -------------------------------------------------------------------- +# Build NDFC Fabric Access Port-Channel Interfaces List From Template +# -------------------------------------------------------------------- + +- name: Build NDFC Fabric Access Port-Channel Interfaces List From Template + ansible.builtin.include_tasks: ndfc_interface_access_po.yml + +# -------------------------------------------------------------------- +# Build NDFC Fabric Trunk Port-Channel Interfaces List From Template +# -------------------------------------------------------------------- + +- name: Build NDFC Fabric Trunk Port-Channel Interfaces List From Template + ansible.builtin.include_tasks: ndfc_interface_trunk_po.yml + +# -------------------------------------------------------------------- +# Build NDFC Fabric Interface Routed List From Template +# -------------------------------------------------------------------- + +- name: Build NDFC Fabric Interface Routed List From Template + ansible.builtin.include_tasks: ndfc_interface_routed.yml + +# -------------------------------------------------------------------- +# Build NDFC Fabric Sub-Interface Routed List From Template +# -------------------------------------------------------------------- + +- name: Build NDFC Fabric Sub-Interface Routed List From Template + ansible.builtin.include_tasks: ndfc_sub_interface_routed.yml + +# -------------------------------------------------------------------- +# Build NDFC Fabric Routed Port-Channel Interface List From Template +# -------------------------------------------------------------------- + +- name: Build NDFC Fabric Routed Port-Channel Interface List From Template + ansible.builtin.include_tasks: ndfc_interface_po_routed.yml + +# -------------------------------------------------------------------- +# Build Trunk Interfaces List From Template +# -------------------------------------------------------------------- + +- name: Build Trunk Interfaces List From Template + ansible.builtin.include_tasks: ndfc_interface_trunk.yml + +# -------------------------------------------------------------------- +# Build Access Interfaces List From Template +# -------------------------------------------------------------------- + +- name: Build Access Interfaces List From Template + ansible.builtin.include_tasks: ndfc_interface_access.yml + +# -------------------------------------------------------------------- +# Build Fabric interface VPC List From Template +# -------------------------------------------------------------------- + +- name: Build Fabric interface VPC List From Template + ansible.builtin.include_tasks: ndfc_interface_vpc.yml + +# -------------------------------------------------------------------- +# Build Fabric interface all List From Template +# -------------------------------------------------------------------- + +- name: Build Fabric interface All List From Template + ansible.builtin.include_tasks: ndfc_interface_all.yml \ No newline at end of file diff --git a/roles/dtc/create/README.md b/roles/dtc/create/README.md index 777edd0f..a6d2ed13 100644 --- a/roles/dtc/create/README.md +++ b/roles/dtc/create/README.md @@ -27,6 +27,22 @@ Example Playbook - role: cisco.nac_dc_vxlan.dtc.create ``` +------- +The following tags can be used to selectively execute stages within the `cisco.nac_dc_vxlan.create` role + +`cr` stands for `create_role` + +* cr_manage_fabric +* cr_manage_switches +* cr_manage_vpc_peers +* cr_manage_interfaces +* cr_manage_vrfs_networks + +```bash +# Selectively run stage to add VRFs and Networks and skip all other stages +ansible-playbook -i inventory.yml vxlan.yml --tags cr_manage_vrfs_networks +``` + License ------- diff --git a/roles/dtc/create/meta/main.yml b/roles/dtc/create/meta/main.yml index d2bface5..7afbb83d 100644 --- a/roles/dtc/create/meta/main.yml +++ b/roles/dtc/create/meta/main.yml @@ -27,4 +27,5 @@ galaxy_info: dependencies: - cisco.nac_dc_vxlan.validate + - cisco.nac_dc_vxlan.common_global - cisco.nac_dc_vxlan.dtc.common diff --git a/roles/dtc/create/tasks/main.yml b/roles/dtc/create/tasks/main.yml index ef5564af..2d1c3fe1 100644 --- a/roles/dtc/create/tasks/main.yml +++ b/roles/dtc/create/tasks/main.yml @@ -21,47 +21,5 @@ --- -- name: Role Entry Point - [cisco.nac_dc_vxlan.dtc.create] - ansible.builtin.debug: - msg: - - "----------------------------------------------------------------" - - "+ Calling Role - [cisco.nac_dc_vxlan.dtc.create] +" - - "----------------------------------------------------------------" - -- ansible.builtin.debug: msg="Configuring NXOS Devices using NDFC (Direct to Controller)" - -- name: Create NDFC Fabric - ansible.builtin.include_tasks: fabric.yml - when: MD_Extended.vxlan.global is defined - -- name: Manage NDFC Fabric Switches - ansible.builtin.include_tasks: devices.yml - when: MD_Extended.vxlan.topology.switches | length > 0 - -- name: Manage VPC Peering - ansible.builtin.include_tasks: vpc_peering.yml - when: MD_Extended.vxlan.topology.vpc_peers | length > 0 - -- name: Manage NDFC Fabric Interfaces - ansible.builtin.include_tasks: interfaces.yml - when: (MD_Extended.vxlan.topology.interfaces.modes.all.count >0) and (MD_Extended.vxlan.topology.switches | length > 0) - -- name: Manage NDFC Fabric VRFs and Networks - ansible.builtin.include_tasks: vrfs_networks.yml - when: (MD.vxlan.overlay_services is defined) and (MD_Extended.vxlan.topology.switches | length > 0) - -# - name: Manage NDFC VRF-Lite Extensions -# ansible.builtin.include_tasks: vrflite.yml -# when: MD.vxlan is defined - -# - name: Manage NDFC Templates -# ansible.builtin.include_tasks: templates.yml -# when: MD.vxlan is defined - -# - name: Manage NDFC Policies -# ansible.builtin.include_tasks: policies.yml -# when: MD.vxlan is defined - -# Other areas to enable -# 1. Diff between git source data model files and only call stage that is needed. -# 2. Build data model from NDFC queries (brown field) DTC feature only +- name: Import Role Tasks + ansible.builtin.import_tasks: sub_main.yml diff --git a/roles/dtc/create/tasks/sub_main.yml b/roles/dtc/create/tasks/sub_main.yml new file mode 100644 index 00000000..12a7b83d --- /dev/null +++ b/roles/dtc/create/tasks/sub_main.yml @@ -0,0 +1,58 @@ +# Copyright (c) 2024 Cisco Systems, Inc. and its affiliates +# +# Permission is hereby granted, free of charge, to any person obtaining a copy of +# this software and associated documentation files (the "Software"), to deal in +# the Software without restriction, including without limitation the rights to +# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +# the Software, and to permit persons to whom the Software is furnished to do so, +# subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +# +# SPDX-License-Identifier: MIT + +--- + +- name: Role Entry Point - [cisco.nac_dc_vxlan.dtc.create] + ansible.builtin.debug: + msg: + - "----------------------------------------------------------------" + - "+ Calling Role - [cisco.nac_dc_vxlan.dtc.create] +" + - "----------------------------------------------------------------" + tags: "{{ nac_tags.create }}" # Tags defined in roles/common_global/vars/main.yml + +- ansible.builtin.debug: msg="Configuring NXOS Devices using NDFC (Direct to Controller)" + tags: "{{ nac_tags.create }}" + +- name: Create NDFC Fabric + ansible.builtin.import_tasks: fabric.yml + when: MD_Extended.vxlan.global is defined + tags: "{{ nac_tags.create_fabric }}" + +- name: Manage NDFC Fabric Switches + ansible.builtin.import_tasks: devices.yml + when: MD_Extended.vxlan.topology.switches | length > 0 + tags: "{{ nac_tags.create_switches }}" + +- name: Manage VPC Peering + ansible.builtin.import_tasks: vpc_peering.yml + when: MD_Extended.vxlan.topology.vpc_peers | length > 0 + tags: "{{ nac_tags.create_vpc_peers }}" + +- name: Manage NDFC Fabric Interfaces + ansible.builtin.import_tasks: interfaces.yml + when: (MD_Extended.vxlan.topology.interfaces.modes.all.count >0) and (MD_Extended.vxlan.topology.switches | length > 0) + tags: "{{ nac_tags.create_interfaces }}" + +- name: Manage NDFC Fabric VRFs and Networks + ansible.builtin.import_tasks: vrfs_networks.yml + when: (MD.vxlan.overlay_services is defined) and (MD_Extended.vxlan.topology.switches | length > 0) + tags: "{{ nac_tags.create_vrfs_networks }}" diff --git a/roles/dtc/create/tasks/vpc_peering.yml b/roles/dtc/create/tasks/vpc_peering.yml index 8610fcce..a5ab3a56 100644 --- a/roles/dtc/create/tasks/vpc_peering.yml +++ b/roles/dtc/create/tasks/vpc_peering.yml @@ -21,6 +21,13 @@ --- +- name: Manage Fabric vPC Peers Entry Point + ansible.builtin.debug: + msg: + - "----------------------------------------------------------------" + - "+ Manage Fabric vPC Peers {{ MD.vxlan.global.name }}" + - "----------------------------------------------------------------" + # -------------------------------------------------------------------- # Manage Intra Fabric Links Configuration on NDFC (prepare links for vpc peering) # -------------------------------------------------------------------- diff --git a/roles/dtc/deploy/meta/main.yml b/roles/dtc/deploy/meta/main.yml index 56141df5..a8d23bea 100644 --- a/roles/dtc/deploy/meta/main.yml +++ b/roles/dtc/deploy/meta/main.yml @@ -27,4 +27,5 @@ galaxy_info: dependencies: - 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 e4199984..93eafc06 100644 --- a/roles/dtc/deploy/tasks/main.yml +++ b/roles/dtc/deploy/tasks/main.yml @@ -21,28 +21,6 @@ --- -- name: Role Entry Point - [cisco.nac_dc_vxlan.dtc.deploy] - ansible.builtin.debug: - msg: - - "----------------------------------------------------------------" - - "+ Calling Role - [cisco.nac_dc_vxlan.dtc.deploy] +" - - "----------------------------------------------------------------" - -- ansible.builtin.debug: msg="Configuring NXOS Devices using NDFC (Direct to Controller)" - -- name: Config-Save for Fabric {{ MD.vxlan.global.name }} - cisco.dcnm.dcnm_rest: - method: POST - path: "/appcenter/cisco/ndfc/api/v1/lan-fabric/rest/control/fabrics/{{ MD.vxlan.global.name }}/config-save" - when: MD_Extended.vxlan.topology.switches | length > 0 - # TODO: Need to add logic to only save if changes are made - -- name: Deploy for Fabric {{ MD.vxlan.global.name }} - cisco.dcnm.dcnm_rest: - path: "/appcenter/cisco/ndfc/api/v1/lan-fabric/rest/control/fabrics/{{ MD.vxlan.global.name }}/config-deploy?forceShowRun=false" - method: POST - vars: - ansible_command_timeout: 3000 - ansible_connect_timeout: 3000 - when: MD_Extended.vxlan.topology.switches | length > 0 - # TODO: Need to add logic to only deploy if changes are made +- name: Import Role Tasks + ansible.builtin.import_tasks: sub_main.yml + tags: "{{ nac_tags.create }}" # Tags defined in roles/common_global/vars/main.yml \ No newline at end of file diff --git a/roles/dtc/deploy/tasks/sub_main.yml b/roles/dtc/deploy/tasks/sub_main.yml new file mode 100644 index 00000000..c45587cd --- /dev/null +++ b/roles/dtc/deploy/tasks/sub_main.yml @@ -0,0 +1,48 @@ +# Copyright (c) 2024 Cisco Systems, Inc. and its affiliates +# +# Permission is hereby granted, free of charge, to any person obtaining a copy of +# this software and associated documentation files (the "Software"), to deal in +# the Software without restriction, including without limitation the rights to +# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +# the Software, and to permit persons to whom the Software is furnished to do so, +# subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +# +# SPDX-License-Identifier: MIT + +--- + +- name: Role Entry Point - [cisco.nac_dc_vxlan.dtc.deploy] + ansible.builtin.debug: + msg: + - "----------------------------------------------------------------" + - "+ Calling Role - [cisco.nac_dc_vxlan.dtc.deploy] +" + - "----------------------------------------------------------------" + +- ansible.builtin.debug: msg="Configuring NXOS Devices using NDFC (Direct to Controller)" + +- name: Config-Save for Fabric {{ MD.vxlan.global.name }} + cisco.dcnm.dcnm_rest: + method: POST + path: "/appcenter/cisco/ndfc/api/v1/lan-fabric/rest/control/fabrics/{{ MD.vxlan.global.name }}/config-save" + when: MD_Extended.vxlan.topology.switches | length > 0 + # TODO: Need to add logic to only save if changes are made + +- name: Deploy for Fabric {{ MD.vxlan.global.name }} + cisco.dcnm.dcnm_rest: + path: "/appcenter/cisco/ndfc/api/v1/lan-fabric/rest/control/fabrics/{{ MD.vxlan.global.name }}/config-deploy?forceShowRun=false" + method: POST + vars: + ansible_command_timeout: 3000 + ansible_connect_timeout: 3000 + when: MD_Extended.vxlan.topology.switches | length > 0 + # TODO: Need to add logic to only deploy if changes are made \ No newline at end of file diff --git a/roles/dtc/remove/README.md b/roles/dtc/remove/README.md index ce17a17c..5cde68b7 100644 --- a/roles/dtc/remove/README.md +++ b/roles/dtc/remove/README.md @@ -27,6 +27,23 @@ Example Playbook - role: cisco.nac_dc_vxlan.dtc.remove ``` +------- +The following tags can be used to selectively execute stages within the `cisco.nac_dc_vxlan.create` role + +`rr` stands for `remove_role` + +* rr_manage_interfaces +* rr_manage_networks +* rr_manage_vrfs +* rr_manage_vpc_peers +* rr_manage_links +* rr_manage_switches + +```bash +# Selectively run stage to remove networks and vrfs and skip all other stages +ansible-playbook -i inventory.yml vxlan.yml --tags "rr_manage_networks, rr_manage_vrfs" +``` + License ------- diff --git a/roles/dtc/remove/meta/main.yml b/roles/dtc/remove/meta/main.yml index 0ed54004..02d7de21 100644 --- a/roles/dtc/remove/meta/main.yml +++ b/roles/dtc/remove/meta/main.yml @@ -27,4 +27,5 @@ galaxy_info: dependencies: - cisco.nac_dc_vxlan.validate + - cisco.nac_dc_vxlan.common_global - cisco.nac_dc_vxlan.dtc.common diff --git a/roles/dtc/remove/tasks/interfaces.yml b/roles/dtc/remove/tasks/interfaces.yml new file mode 100644 index 00000000..57f28df1 --- /dev/null +++ b/roles/dtc/remove/tasks/interfaces.yml @@ -0,0 +1,44 @@ +# Copyright (c) 2024 Cisco Systems, Inc. and its affiliates +# +# Permission is hereby granted, free of charge, to any person obtaining a copy of +# this software and associated documentation files (the "Software"), to deal in +# the Software without restriction, including without limitation the rights to +# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +# the Software, and to permit persons to whom the Software is furnished to do so, +# subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +# +# SPDX-License-Identifier: MIT +--- + +- ansible.builtin.debug: msg="Removing all Unmanaged Fabric Interfaces. This could take several minutes..." + when: + - switch_list.response.DATA | length > 0 + - (interface_delete_mode is defined) and (interface_delete_mode is true|bool) + +- cisco.dcnm.dcnm_interface: + fabric: "{{ MD.vxlan.global.name }}" + state: overridden + config: "{{ interface_all }}" + vars: + ansible_command_timeout: 3000 + ansible_connect_timeout: 3000 + when: + - switch_list.response.DATA | length > 0 + - (interface_delete_mode is defined) and (interface_delete_mode is true|bool) + +- ansible.builtin.debug: + msg: + - "-------------------------------------------------------------------------------------------------------------------" + - "+ SKIPPING Remove Unmanaged Fabric Interfaces task because interface_delete_mode flag is set to False +" + - "-------------------------------------------------------------------------------------------------------------------" + when: not ((interface_delete_mode is defined) and (interface_delete_mode is true|bool)) diff --git a/roles/dtc/remove/tasks/links.yml b/roles/dtc/remove/tasks/links.yml new file mode 100644 index 00000000..39677bac --- /dev/null +++ b/roles/dtc/remove/tasks/links.yml @@ -0,0 +1,38 @@ +# Copyright (c) 2024 Cisco Systems, Inc. and its affiliates +# +# Permission is hereby granted, free of charge, to any person obtaining a copy of +# this software and associated documentation files (the "Software"), to deal in +# the Software without restriction, including without limitation the rights to +# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +# the Software, and to permit persons to whom the Software is furnished to do so, +# subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +# +# SPDX-License-Identifier: MIT +--- + +- ansible.builtin.debug: msg="Removing all Unmanaged links. This could take several minutes..." + when: + - switch_list.response.DATA | length > 0 + - (link_vpc_delete_mode is defined) and (link_vpc_delete_mode is true|bool) + +- name: Remove Intra Fabric Links for vpc peering + cisco.dcnm.dcnm_links: + state: replaced + src_fabric: "{{ MD_Extended.vxlan.global.name }}" + config: "{{ link_vpc_peering }}" + vars: + ansible_command_timeout: 3000 + ansible_connect_timeout: 3000 + when: + - switch_list.response.DATA | length > 0 + - (link_vpc_delete_mode is defined) and (link_vpc_delete_mode is true|bool) diff --git a/roles/dtc/remove/tasks/main.yml b/roles/dtc/remove/tasks/main.yml index 745ce1ae..2d1c3fe1 100644 --- a/roles/dtc/remove/tasks/main.yml +++ b/roles/dtc/remove/tasks/main.yml @@ -21,130 +21,5 @@ --- -- name: Role Entry Point - [cisco.nac_dc_vxlan.dtc.remove] - ansible.builtin.debug: - msg: - - "----------------------------------------------------------------" - - "+ Calling Role - [cisco.nac_dc_vxlan.dtc.remove] +" - - "----------------------------------------------------------------" - -- ansible.builtin.debug: msg="Configuring NXOS Devices using NDFC (Direct to Controller)" - -- ansible.builtin.debug: msg="Query NDFC for List of Fabric Switches" - -- cisco.dcnm.dcnm_rest: - method: GET - path: "/appcenter/cisco/ndfc/api/v1/lan-fabric/rest/control/fabrics/{{ MD.vxlan.global.name }}/inventory/switchesByFabric" - register: switch_list - -- ansible.builtin.debug: msg="Removing all Unmanaged Fabric Interfaces. This could take several minutes..." - -- cisco.dcnm.dcnm_interface: - fabric: "{{ MD.vxlan.global.name }}" - state: overridden - config: "{{ interface_all }}" - vars: - ansible_command_timeout: 3000 - ansible_connect_timeout: 3000 - when: - - switch_list.response.DATA | length > 0 - - (interface_delete_mode is defined) and (interface_delete_mode is true|bool) - -- ansible.builtin.debug: msg="Removing Unmanaged Fabric Networks. This could take several minutes..." - -- cisco.dcnm.dcnm_network: - fabric: "{{ MD.vxlan.global.name }}" - state: overridden - config: "{{ net_config }}" - when: - - switch_list.response.DATA | length > 0 - - (network_delete_mode is defined) and (network_delete_mode is true|bool) - -- ansible.builtin.debug: msg="Removing Unmanaged Fabric VRFs. This could take several minutes..." - -- cisco.dcnm.dcnm_vrf: - fabric: "{{ MD.vxlan.global.name }}" - state: overridden - config: "{{ vrf_config }}" - when: - - switch_list.response.DATA | length > 0 - - (vrf_delete_mode is defined) and (vrf_delete_mode is true|bool) - -- ansible.builtin.debug: msg="Removing all Unmanaged vPC Peering. This could take several minutes..." - -- name: Remove vPC Peering - cisco.dcnm.dcnm_vpc_pair: - src_fabric: "{{ MD.vxlan.global.name }}" - deploy: true - state: overridden - config: "{{ vpc_peering }}" - vars: - ansible_command_timeout: 1000 - ansible_connect_timeout: 1000 - when: - - switch_list.response.DATA | length > 0 - - (vpc_delete_mode is defined) and (vpc_delete_mode is true|bool) - -- ansible.builtin.debug: msg="Removing all Unmanaged links. This could take several minutes..." - -- name: Remove Intra Fabric Links for vpc peering - cisco.dcnm.dcnm_links: - state: replaced - src_fabric: "{{ MD_Extended.vxlan.global.name }}" - config: "{{ link_vpc_peering }}" - vars: - ansible_command_timeout: 3000 - ansible_connect_timeout: 3000 - when: - - switch_list.response.DATA | length > 0 - - (link_vpc_delete_mode is defined) and (link_vpc_delete_mode is true|bool) - -- ansible.builtin.debug: msg="Removing Unmanaged Fabric Switches. This could take several minutes..." - -- name: Remove NDFC Fabric Devices {{ MD.vxlan.global.name }} - cisco.dcnm.dcnm_inventory: - fabric: "{{ MD.vxlan.global.name }}" - config: "{{ updated_inv_config['updated_inv_list'] }}" - deploy: true - save: true - state: overridden - vars: - ansible_command_timeout: 3000 - ansible_connect_timeout: 3000 - when: - - (inventory_delete_mode is defined) and (inventory_delete_mode is true|bool) - -- ansible.builtin.debug: - msg: - - "-------------------------------------------------------------------------------------------------------------------" - - "+ SKIPPING Remove Unmanaged Fabric Interfaces task because interface_delete_mode flag is set to False +" - - "-------------------------------------------------------------------------------------------------------------------" - when: not ((interface_delete_mode is defined) and (interface_delete_mode is true|bool)) - -- ansible.builtin.debug: - msg: - - "---------------------------------------------------------------------------------------------------------------" - - "+ SKIPPING Remove Unmanaged Fabric Networks task because network_delete_mode flag is set to False +" - - "---------------------------------------------------------------------------------------------------------------" - when: not ((network_delete_mode is defined) and (network_delete_mode is true|bool)) - -- ansible.builtin.debug: - msg: - - "--------------------------------------------------------------------------------------------------------" - - "+ SKIPPING Remove Unmanaged Fabric VRFs task because vrf_delete_mode flag is set to False +" - - "--------------------------------------------------------------------------------------------------------" - when: not ((vrf_delete_mode is defined) and (vrf_delete_mode is true|bool)) - -- ansible.builtin.debug: - msg: - - "-------------------------------------------------------------------------------------------------------" - - "+ SKIPPING Remove Unmanaged vPC Peering task because vpc_peering_delete_mode flag is set to False +" - - "-------------------------------------------------------------------------------------------------------" - when: not ((vpc_peering_delete_mode is defined) and (vpc_peering_delete_mode is true|bool)) - -- ansible.builtin.debug: - msg: - - "----------------------------------------------------------------------------------------------------------" - - "+ SKIPPING Remove NDFC Fabric Devices task because inventory_delete_mode flag is set to False +" - - "----------------------------------------------------------------------------------------------------------" - when: not ((inventory_delete_mode is defined) and (inventory_delete_mode is true|bool)) +- name: Import Role Tasks + ansible.builtin.import_tasks: sub_main.yml diff --git a/roles/dtc/remove/tasks/networks.yml b/roles/dtc/remove/tasks/networks.yml new file mode 100644 index 00000000..3ae54cdd --- /dev/null +++ b/roles/dtc/remove/tasks/networks.yml @@ -0,0 +1,44 @@ +# Copyright (c) 2024 Cisco Systems, Inc. and its affiliates +# +# Permission is hereby granted, free of charge, to any person obtaining a copy of +# this software and associated documentation files (the "Software"), to deal in +# the Software without restriction, including without limitation the rights to +# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +# the Software, and to permit persons to whom the Software is furnished to do so, +# subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +# +# SPDX-License-Identifier: MIT +--- + +- ansible.builtin.debug: msg="Removing Unmanaged Fabric Networks. This could take several minutes..." + when: + - switch_list.response.DATA | length > 0 + - (network_delete_mode is defined) and (network_delete_mode is true|bool) + +- cisco.dcnm.dcnm_network: + fabric: "{{ MD.vxlan.global.name }}" + state: overridden + config: "{{ net_config }}" + vars: + ansible_command_timeout: 3000 + ansible_connect_timeout: 3000 + when: + - switch_list.response.DATA | length > 0 + - (network_delete_mode is defined) and (network_delete_mode is true|bool) + +- ansible.builtin.debug: + msg: + - "---------------------------------------------------------------------------------------------------------------" + - "+ SKIPPING Remove Unmanaged Fabric Networks task because network_delete_mode flag is set to False +" + - "---------------------------------------------------------------------------------------------------------------" + when: not ((network_delete_mode is defined) and (network_delete_mode is true|bool)) diff --git a/roles/dtc/remove/tasks/sub_main.yml b/roles/dtc/remove/tasks/sub_main.yml new file mode 100644 index 00000000..5cb45a5c --- /dev/null +++ b/roles/dtc/remove/tasks/sub_main.yml @@ -0,0 +1,66 @@ +# Copyright (c) 2024 Cisco Systems, Inc. and its affiliates +# +# Permission is hereby granted, free of charge, to any person obtaining a copy of +# this software and associated documentation files (the "Software"), to deal in +# the Software without restriction, including without limitation the rights to +# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +# the Software, and to permit persons to whom the Software is furnished to do so, +# subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +# +# SPDX-License-Identifier: MIT + +--- + +- name: Role Entry Point - [cisco.nac_dc_vxlan.dtc.remove] + ansible.builtin.debug: + msg: + - "----------------------------------------------------------------" + - "+ Calling Role - [cisco.nac_dc_vxlan.dtc.remove] +" + - "----------------------------------------------------------------" + tags: "{{ nac_tags.remove }}" # Tags defined in roles/common_global/vars/main.yml + +- ansible.builtin.debug: msg="Configuring NXOS Devices using NDFC (Direct to Controller)" + tags: "{{ nac_tags.remove }}" + +- ansible.builtin.debug: msg="Query NDFC for List of Fabric Switches" + tags: "{{ nac_tags.remove }}" + +- cisco.dcnm.dcnm_rest: + method: GET + path: "/appcenter/cisco/ndfc/api/v1/lan-fabric/rest/control/fabrics/{{ MD.vxlan.global.name }}/inventory/switchesByFabric" + register: switch_list + tags: "{{ nac_tags.remove }}" + +- name: Remove Fabric Interfaces + ansible.builtin.import_tasks: interfaces.yml + tags: "{{ nac_tags.remove_interfaces }}" + +- name: Remove Fabric Networks + ansible.builtin.import_tasks: networks.yml + tags: "{{ nac_tags.remove_networks }}" + +- name: Remove Fabric VRFs + ansible.builtin.import_tasks: vrfs.yml + tags: "{{ nac_tags.remove_vrfs }}" + +- name: Remove Fabric vPC Peering + ansible.builtin.import_tasks: vpc_peers.yml + tags: "{{ nac_tags.remove_vpc_peers }}" + +- name: Remove Fabric Links + ansible.builtin.import_tasks: links.yml + tags: "{{ nac_tags.remove_links }}" + +- name: Remove Fabric Switches + ansible.builtin.import_tasks: switches.yml + tags: "{{ nac_tags.remove_switches }}" \ No newline at end of file diff --git a/roles/dtc/remove/tasks/switches.yml b/roles/dtc/remove/tasks/switches.yml new file mode 100644 index 00000000..d7e70044 --- /dev/null +++ b/roles/dtc/remove/tasks/switches.yml @@ -0,0 +1,45 @@ +# Copyright (c) 2024 Cisco Systems, Inc. and its affiliates +# +# Permission is hereby granted, free of charge, to any person obtaining a copy of +# this software and associated documentation files (the "Software"), to deal in +# the Software without restriction, including without limitation the rights to +# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +# the Software, and to permit persons to whom the Software is furnished to do so, +# subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +# +# SPDX-License-Identifier: MIT +--- + +- ansible.builtin.debug: msg="Removing Unmanaged Fabric Switches. This could take several minutes..." + when: + - (inventory_delete_mode is defined) and (inventory_delete_mode is true|bool) + +- name: Remove NDFC Fabric Devices {{ MD.vxlan.global.name }} + cisco.dcnm.dcnm_inventory: + fabric: "{{ MD.vxlan.global.name }}" + config: "{{ updated_inv_config['updated_inv_list'] }}" + deploy: true + save: true + state: overridden + vars: + ansible_command_timeout: 3000 + ansible_connect_timeout: 3000 + when: + - (inventory_delete_mode is defined) and (inventory_delete_mode is true|bool) + +- ansible.builtin.debug: + msg: + - "----------------------------------------------------------------------------------------------------------" + - "+ SKIPPING Remove NDFC Fabric Devices task because inventory_delete_mode flag is set to False +" + - "----------------------------------------------------------------------------------------------------------" + when: not ((inventory_delete_mode is defined) and (inventory_delete_mode is true|bool)) \ No newline at end of file diff --git a/roles/dtc/remove/tasks/vpc_peers.yml b/roles/dtc/remove/tasks/vpc_peers.yml new file mode 100644 index 00000000..3d798217 --- /dev/null +++ b/roles/dtc/remove/tasks/vpc_peers.yml @@ -0,0 +1,46 @@ +# Copyright (c) 2024 Cisco Systems, Inc. and its affiliates +# +# Permission is hereby granted, free of charge, to any person obtaining a copy of +# this software and associated documentation files (the "Software"), to deal in +# the Software without restriction, including without limitation the rights to +# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +# the Software, and to permit persons to whom the Software is furnished to do so, +# subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +# +# SPDX-License-Identifier: MIT +--- + +- ansible.builtin.debug: msg="Removing all Unmanaged vPC Peering. This could take several minutes..." + when: + - switch_list.response.DATA | length > 0 + - (vpc_delete_mode is defined) and (vpc_delete_mode is true|bool) + +- name: Remove vPC Peering + cisco.dcnm.dcnm_vpc_pair: + src_fabric: "{{ MD.vxlan.global.name }}" + deploy: true + state: overridden + config: "{{ vpc_peering }}" + vars: + ansible_command_timeout: 1000 + ansible_connect_timeout: 1000 + when: + - switch_list.response.DATA | length > 0 + - (vpc_delete_mode is defined) and (vpc_delete_mode is true|bool) + +- ansible.builtin.debug: + msg: + - "-------------------------------------------------------------------------------------------------------" + - "+ SKIPPING Remove Unmanaged vPC Peering task because vpc_peering_delete_mode flag is set to False +" + - "-------------------------------------------------------------------------------------------------------" + when: not ((vpc_peering_delete_mode is defined) and (vpc_peering_delete_mode is true|bool)) diff --git a/roles/dtc/remove/tasks/vrfs.yml b/roles/dtc/remove/tasks/vrfs.yml new file mode 100644 index 00000000..83aa51b3 --- /dev/null +++ b/roles/dtc/remove/tasks/vrfs.yml @@ -0,0 +1,44 @@ +# Copyright (c) 2024 Cisco Systems, Inc. and its affiliates +# +# Permission is hereby granted, free of charge, to any person obtaining a copy of +# this software and associated documentation files (the "Software"), to deal in +# the Software without restriction, including without limitation the rights to +# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +# the Software, and to permit persons to whom the Software is furnished to do so, +# subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +# +# SPDX-License-Identifier: MIT +--- + +- ansible.builtin.debug: msg="Removing Unmanaged Fabric VRFs. This could take several minutes..." + when: + - switch_list.response.DATA | length > 0 + - (vrf_delete_mode is defined) and (vrf_delete_mode is true|bool) + +- cisco.dcnm.dcnm_vrf: + fabric: "{{ MD.vxlan.global.name }}" + state: overridden + config: "{{ vrf_config }}" + vars: + ansible_command_timeout: 3000 + ansible_connect_timeout: 3000 + when: + - switch_list.response.DATA | length > 0 + - (vrf_delete_mode is defined) and (vrf_delete_mode is true|bool) + +- ansible.builtin.debug: + msg: + - "--------------------------------------------------------------------------------------------------------" + - "+ SKIPPING Remove Unmanaged Fabric VRFs task because vrf_delete_mode flag is set to False +" + - "--------------------------------------------------------------------------------------------------------" + when: not ((vrf_delete_mode is defined) and (vrf_delete_mode is true|bool)) diff --git a/roles/validate/meta/main.yml b/roles/validate/meta/main.yml index fccaf260..22774274 100644 --- a/roles/validate/meta/main.yml +++ b/roles/validate/meta/main.yml @@ -25,4 +25,4 @@ galaxy_info: license: LICENSE min_ansible_version: 2.14.15 -dependencies: [] +dependencies: [cisco.nac_dc_vxlan.common_global] diff --git a/roles/validate/tasks/main.yml b/roles/validate/tasks/main.yml index 6178d2a5..23badea6 100644 --- a/roles/validate/tasks/main.yml +++ b/roles/validate/tasks/main.yml @@ -20,98 +20,7 @@ # SPDX-License-Identifier: MIT --- -- name: Role Entry Point - [cisco.nac_dc_vxlan.validate] - ansible.builtin.debug: - msg: - - "----------------------------------------------------------------" - - "+ Calling Role - [cisco.nac_dc_vxlan.validate] +" - - "----------------------------------------------------------------" -- ansible.builtin.debug: msg="Role Path - {{ role_path }}" - -- ansible.builtin.debug: msg="Inventory Directory - {{ inventory_dir }}" - -- name: Validate NDFC Service Model Data - block: - - ansible.builtin.debug: msg="Calling Role Validate - nac_dc_vxlan.validate" - - - ansible.builtin.debug: msg="Workflow is Direct to Device (DTD)" - when: hostvars[inventory_hostname]['ansible_network_os'] == "cisco.nxos.nxos" - - - ansible.builtin.debug: msg="Workflow is Direct to Controller (DTC)" - when: hostvars[inventory_hostname]['ansible_network_os'] == "cisco.dcnm.dcnm" - - - name: Check for Schema Path Being Defined - ansible.builtin.set_fact: - schema_path: '' - when: schema_path is not defined - delegate_to: localhost - - - name: Check for Enhanced Roles Path Being Defined - ansible.builtin.set_fact: - enhanced_rules_path: '' - when: enhanced_rules_path is not defined - delegate_to: localhost - - - name: Perform Required Syntax and Semantic Model Validation - cisco.nac_dc_vxlan.common.nac_dc_validate: - schema: "{{ schema_path }}" - mdata: "{{ data_path }}" - rules: "{{ rules_path }}" - register: model_data - vars: - data_path: "{{ inventory_dir }}/host_vars/{{ inventory_hostname }}" - rules_path: "{{ role_path }}/files/rules/required_rules/" - delegate_to: localhost - - - name: Perform Enhanced Syntax and Semantic Model Validation - cisco.nac_dc_vxlan.common.nac_dc_validate: - schema: "{{ schema_path }}" - mdata: "{{ data_path }}" - rules: "{{ enhanced_rules_path }}" - vars: - data_path: "{{ inventory_dir }}/host_vars/{{ inventory_hostname }}" - delegate_to: localhost - - - name: Prepare Service Model - cisco.nac_dc_vxlan.common.prepare_service_model: - inventory_hostname: "{{ inventory_hostname }}" - hostvars: "{{ hostvars }}" - model_data: "{{ model_data['data'] }}" - register: smd - delegate_to: localhost - - - name: Store Golden Service Model Data - ansible.builtin.set_fact: - MD: "{{ smd['model_golden'] }}" - delegate_to: localhost - - - name: Store Extended Service Model Data - ansible.builtin.set_fact: - MD_Extended: "{{ smd['model_extended'] }}" - delegate_to: localhost - - - name: Check Roles - cisco.nac_dc_vxlan.common.check_roles: - role_list: "{{ role_names }}" - register: check_roles - delegate_to: localhost - - - name: Manage Previous Service Model Data Files - ansible.builtin.include_tasks: manage_model_files_previous.yml - when: check_roles['save_previous'] - - - name: Manage Current Service Model Data Files - ansible.builtin.include_tasks: manage_model_files_current.yml - when: check_roles['save_previous'] - - - name: Stat Host Specific Defaults - ansible.builtin.stat: path="{{ role_path }}/defaults/{{ inventory_hostname }}/defaults.yml" - register: host_defaults - delegate_to: localhost - - - name: Include Host Specific Defaults if Available - ansible.builtin.include_vars: - file: "{{ role_path }}/defaults/{{ inventory_hostname }}/defaults.yml" - when: host_defaults.stat.exists - delegate_to: localhost +- name: Import Role Tasks + ansible.builtin.import_tasks: sub_main.yml + tags: "{{ nac_tags.all }}" # Tags defined in roles/common_global/vars/main.yml diff --git a/roles/validate/tasks/sub_main.yml b/roles/validate/tasks/sub_main.yml new file mode 100644 index 00000000..f6e837fa --- /dev/null +++ b/roles/validate/tasks/sub_main.yml @@ -0,0 +1,116 @@ +# Copyright (c) 2024 Cisco Systems, Inc. and its affiliates +# +# Permission is hereby granted, free of charge, to any person obtaining a copy of +# this software and associated documentation files (the "Software"), to deal in +# the Software without restriction, including without limitation the rights to +# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +# the Software, and to permit persons to whom the Software is furnished to do so, +# subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +# +# SPDX-License-Identifier: MIT + +--- +- name: Role Entry Point - [cisco.nac_dc_vxlan.validate] + ansible.builtin.debug: + msg: + - "----------------------------------------------------------------" + - "+ Calling Role - [cisco.nac_dc_vxlan.validate] +" + - "----------------------------------------------------------------" + +- ansible.builtin.debug: msg="Role Path - {{ role_path }}" + +- ansible.builtin.debug: msg="Inventory Directory - {{ inventory_dir }}" + +- name: Validate NDFC Service Model Data + ansible.builtin.debug: msg="Calling Role Validate - nac_dc_vxlan.validate" + +- ansible.builtin.debug: msg="Workflow is Direct to Device (DTD)" + when: hostvars[inventory_hostname]['ansible_network_os'] == "cisco.nxos.nxos" + +- ansible.builtin.debug: msg="Workflow is Direct to Controller (DTC)" + when: hostvars[inventory_hostname]['ansible_network_os'] == "cisco.dcnm.dcnm" + +- name: Check for Schema Path Being Defined + ansible.builtin.set_fact: + schema_path: '' + when: schema_path is not defined + delegate_to: localhost + +- name: Check for Enhanced Roles Path Being Defined + ansible.builtin.set_fact: + enhanced_rules_path: '' + when: enhanced_rules_path is not defined + delegate_to: localhost + +- name: Perform Required Syntax and Semantic Model Validation + cisco.nac_dc_vxlan.common.nac_dc_validate: + schema: "{{ schema_path }}" + mdata: "{{ data_path }}" + rules: "{{ rules_path }}" + register: model_data + vars: + data_path: "{{ inventory_dir }}/host_vars/{{ inventory_hostname }}" + rules_path: "{{ role_path }}/files/rules/required_rules/" + delegate_to: localhost + +- name: Perform Enhanced Syntax and Semantic Model Validation + cisco.nac_dc_vxlan.common.nac_dc_validate: + schema: "{{ schema_path }}" + mdata: "{{ data_path }}" + rules: "{{ enhanced_rules_path }}" + vars: + data_path: "{{ inventory_dir }}/host_vars/{{ inventory_hostname }}" + delegate_to: localhost + +- name: Prepare Service Model + cisco.nac_dc_vxlan.common.prepare_service_model: + inventory_hostname: "{{ inventory_hostname }}" + hostvars: "{{ hostvars }}" + model_data: "{{ model_data['data'] }}" + register: smd + delegate_to: localhost + +- name: Store Golden Service Model Data + ansible.builtin.set_fact: + MD: "{{ smd['model_golden'] }}" + delegate_to: localhost + +- name: Store Extended Service Model Data + ansible.builtin.set_fact: + MD_Extended: "{{ smd['model_extended'] }}" + delegate_to: localhost + +- name: Check Roles + cisco.nac_dc_vxlan.common.check_roles: + role_list: "{{ role_names }}" + register: check_roles + delegate_to: localhost + +- name: Manage Previous Service Model Data Files + ansible.builtin.include_tasks: manage_model_files_previous.yml + when: check_roles['save_previous'] + +- name: Manage Current Service Model Data Files + ansible.builtin.include_tasks: manage_model_files_current.yml + when: check_roles['save_previous'] + +- name: Stat Host Specific Defaults + ansible.builtin.stat: path="{{ role_path }}/defaults/{{ inventory_hostname }}/defaults.yml" + register: host_defaults + delegate_to: localhost + +- name: Include Host Specific Defaults if Available + ansible.builtin.include_vars: + file: "{{ role_path }}/defaults/{{ inventory_hostname }}/defaults.yml" + when: host_defaults.stat.exists + delegate_to: localhost \ No newline at end of file diff --git a/tests/integration/roles/test_common/tasks/main.yml b/tests/integration/roles/test_common/tasks/main.yml index 8a20e1fa..b045a7fa 100644 --- a/tests/integration/roles/test_common/tasks/main.yml +++ b/tests/integration/roles/test_common/tasks/main.yml @@ -22,12 +22,16 @@ --- - ansible.builtin.import_role: name: cisco.nac_dc_vxlan.validate + tags: 'role_validate' - ansible.builtin.import_role: name: cisco.nac_dc_vxlan.dtc.create + tags: 'role_create' - ansible.builtin.import_role: name: cisco.nac_dc_vxlan.dtc.deploy + tags: 'role_deploy' - ansible.builtin.import_role: name: cisco.nac_dc_vxlan.dtc.remove + tags: 'role_remove' diff --git a/tests/integration/roles/test_remove/defaults/main.yml b/tests/integration/roles/test_remove/defaults/main.yml deleted file mode 100644 index 8a3e0513..00000000 --- a/tests/integration/roles/test_remove/defaults/main.yml +++ /dev/null @@ -1,188 +0,0 @@ -# Copyright (c) 2024 Cisco Systems, Inc. and its affiliates -# -# Permission is hereby granted, free of charge, to any person obtaining a copy of -# this software and associated documentation files (the "Software"), to deal in -# the Software without restriction, including without limitation the rights to -# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of -# the Software, and to permit persons to whom the Software is furnished to do so, -# subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in all -# copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS -# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR -# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER -# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -# -# SPDX-License-Identifier: MIT - ---- -defaults: - vxlan: - global: - route_reflectors: 2 - anycast_gateway_mac: 20:20:00:00:00:aa - auth_proto: MD5 - vpc: - peer_link_vlan: 3600 - peer_keep_alive: management - auto_recovery_time: 360 - delay_restore_time: 150 - peer_link_port_channel_id: 500 - advertise_pip: false - advertise_pip_border_only: true - domain_id_range: 1-1000 - topology: - switches: - routing_loopback_id: 0 - vtep_loopback_id: 1 - interfaces: - topology_switch_access_interface: - description: 'NetAsCode Access Interface' - mtu: jumbo - speed: auto - enabled: true - access_vlan: 1 - spanning_tree_portfast: true - enable_bpdu_guard: true - topology_switch_trunk_interface: - description: 'NetAsCode Trunk Interface' - mtu: jumbo - speed: auto - enabled: true - trunk_allowed_vlans: none - spanning_tree_portfast: true - enable_bpdu_guard: true - topology_switch_access_po_interface: - description: 'NetAsCode Access PO Interface' - mtu: jumbo - speed: auto - enabled: true - access_vlan: 1 - pc_mode: active - spanning_tree_portfast: true - enable_bpdu_guard: true - topology_switch_trunk_po_interface: - description: 'NetAsCode Trunk PO Interface' - mtu: jumbo - speed: auto - enabled: true - trunk_allowed_vlans: none - pc_mode: active - spanning_tree_portfast: true - enable_bpdu_guard: true - topology_switch_routed_interface: - description: 'NetAsCode Routed Interface' - mtu: 9216 - speed: auto - enabled: true - topology_switch_routed_sub_interface: - description: 'NetAsCode Routed Sub Interface' - mtu: 9216 - speed: auto - enabled: true - topology_switch_routed_po_interface: - description: 'NetAsCode Routed PO Interface' - mtu: 9216 - speed: auto - enabled: true - pc_mode: active - topology_switch_loopback_interface: - description: 'NetAsCode Loopback Interface' - enabled: true - vpc_peers: - domain_id: 1 - fabric_links: - edge_connections: - underlay: - general: - routing_protocol: ospf - enable_ipv6_underlay: false - replication_mode: multicast - fabric_interface_numbering: p2p - subnet_mask: 30 - manual_underlay_allocation: false - underlay_routing_loopback_id: 0 - underlay_vtep_loopback_id: 1 - underlay_routing_protocol_tag: UNDERLAY - underlay_rp_loopback_id: 254 - intra_fabric_interface_mtu: 9216 - layer2_host_interfacde_mtu: 9216 - unshut_host_interfaces: true - ipv4: - underlay_routing_loopback_ip_range: 10.2.0.0/22 - underlay_vtep_loopback_ip_range: 10.3.0.0/22 - underlay_rp_loopback_ip_range: 10.254.254.0/24 - underlay_subnet_ip_range: 10.4.0.0/16 - ipv6: - enable_ipv6_link_local_address: true - underlay_subnet_mask: 126 - ospf: - area_id: 0.0.0.0 - authentication_enable: false - authentication_key_id: 127 - isis: - level: level2 - network_point_to_point: true - authentication_enable: false - authentication_key_id: 127 - overload_bit: true - overload_bit_elapsed_time: 60 - bgp: - authentication_enable: false - authentication_key_type: 3 - multicast: - group_subnet: 239.1.1.0/25 - rendezvous_points: 2 - rp_mode: asm - underlay_rp_loopback_id: 254 - trm_enable: false - trm_default_group: 239.1.1.0 - underlay_primary_rp_loopback_id: 2 - underlay_backup_rp_loopback_id: 3 - underlay_second_backup_rp_loopback_id: 4 - underlay_third_backup_rp_loopback_id: 5 - bfd: - enable: false - ibgp: false - ospf: false - pim: false - isis: false - authentication_enable: false - authentication_key_id: 100 - overlay_services: - vrfs: - vrf_description: "Configured by Ansible NetAsCode" - vrf_int_mtu: 9216 - loopback_route_tag: 12345 - max_bgp_paths: 1 - max_ibgp_paths: 2 - ipv6_linklocal_enable: true - adv_host_routes: false - adv_default_routes: true - static_default_route: true - disable_rt_auto: false - netflow_enable: false - no_rp: false - redist_direct_routemap: FABRIC-RMAP-REDIST-SUBNET - trm_enable: false - trm_bgw_msite: false - networks: - net_description: "Configured by Ansible NetAsCode" - is_l2_only: false - arp_supress: false - l3gw_on_border: false - mtu_l3intf: 9216 - multicast_group_address: 239.1.1.1 - netflow_enable: false - route_target_both: false - route_tag: 12345 - trm_enable: false - vrf_attach_groups: - switches: [] - network_attach_groups: - switches: [] - overlay_extension: diff --git a/tests/integration/test_vxlan_small_sha.yml b/tests/integration/test_vxlan_small_sha.yml index 6d89b1a5..00bc8e10 100644 --- a/tests/integration/test_vxlan_small_sha.yml +++ b/tests/integration/test_vxlan_small_sha.yml @@ -20,7 +20,7 @@ # SPDX-License-Identifier: MIT --- -# This playbook Run tests agains the data under tests/integration/host_vars/fabric_full_small_sha +# This playbook runs tests agains the data under tests/integration/host_vars/fabric_full_small_sha # Instructions for using this playbook: # diff --git a/tests/sanity/ignore-2.14.txt b/tests/sanity/ignore-2.14.txt index 2614ab8a..ba721d80 100644 --- a/tests/sanity/ignore-2.14.txt +++ b/tests/sanity/ignore-2.14.txt @@ -10,6 +10,7 @@ plugins/action/common/prepare_service_model.py action-plugin-docs # action plugi plugins/action/common/get_credentials.py action-plugin-docs # action plugin has no matching module to provide documentation plugins/action/dtc/add_device_check.py action-plugin-docs # action plugin has no matching module to provide documentation plugins/action/dtc/vpc_pair_check.py action-plugin-docs # action plugin has no matching module to provide documentation +plugins/action/dtc/verify_tags.py action-plugin-docs # action plugin has no matching module to provide documentation plugins/action/dtd/prepare_service_model.py action-plugin-docs # action plugin has no matching module to provide documentation plugins/action/test/inventory.py action-plugin-docs # action plugin has no matching module to provide documentation plugins/action/helper_functions.py action-plugin-docs # action plugin has no matching module to provide documentation diff --git a/tests/sanity/ignore-2.15.txt b/tests/sanity/ignore-2.15.txt index 2614ab8a..ba721d80 100644 --- a/tests/sanity/ignore-2.15.txt +++ b/tests/sanity/ignore-2.15.txt @@ -10,6 +10,7 @@ plugins/action/common/prepare_service_model.py action-plugin-docs # action plugi plugins/action/common/get_credentials.py action-plugin-docs # action plugin has no matching module to provide documentation plugins/action/dtc/add_device_check.py action-plugin-docs # action plugin has no matching module to provide documentation plugins/action/dtc/vpc_pair_check.py action-plugin-docs # action plugin has no matching module to provide documentation +plugins/action/dtc/verify_tags.py action-plugin-docs # action plugin has no matching module to provide documentation plugins/action/dtd/prepare_service_model.py action-plugin-docs # action plugin has no matching module to provide documentation plugins/action/test/inventory.py action-plugin-docs # action plugin has no matching module to provide documentation plugins/action/helper_functions.py action-plugin-docs # action plugin has no matching module to provide documentation diff --git a/tests/sanity/ignore-2.16.txt b/tests/sanity/ignore-2.16.txt index 2614ab8a..ba721d80 100644 --- a/tests/sanity/ignore-2.16.txt +++ b/tests/sanity/ignore-2.16.txt @@ -10,6 +10,7 @@ plugins/action/common/prepare_service_model.py action-plugin-docs # action plugi plugins/action/common/get_credentials.py action-plugin-docs # action plugin has no matching module to provide documentation plugins/action/dtc/add_device_check.py action-plugin-docs # action plugin has no matching module to provide documentation plugins/action/dtc/vpc_pair_check.py action-plugin-docs # action plugin has no matching module to provide documentation +plugins/action/dtc/verify_tags.py action-plugin-docs # action plugin has no matching module to provide documentation plugins/action/dtd/prepare_service_model.py action-plugin-docs # action plugin has no matching module to provide documentation plugins/action/test/inventory.py action-plugin-docs # action plugin has no matching module to provide documentation plugins/action/helper_functions.py action-plugin-docs # action plugin has no matching module to provide documentation