netascode / ansible-dc-vxlan

Ansible Collection for configuring a VXLAN Fabric using Direct to Controller (DTC) or Direct To Device (DTD) workflows.
https://galaxy.ansible.com/ui/repo/published/cisco/nac_dc_vxlan/
MIT License
6 stars 6 forks source link

Support for Ansible Tags #133

Closed mikewiebe closed 2 months ago

mikewiebe commented 2 months ago

Summary:

This PR introduces a set of Ansible tags to give users control over which roles in the collection get executed and limited support for which parts of a role get executed. This provides a more flexible framework and performance improvement if users don't need to run all of the stages. For example, if they add a VRF or Network and all of the other state is current, there is no reason to run all of the stages. This allows them to run only VRF and Network stages.

NOTE 1: The tests under the tests/integration folder have been updated to support the tags NOTE 2: The validate and common roles always run regardless of which tag is specified

The following Ansible tags are enabled:

Tags within the roles:


cr stands for create_role

The following tags can be used to selectively execute stages within the cisco.nac_dc_vxlan.create role

# Selectively run stage to add VRFs and Networks and skip all other stages
ansible-playbook -i test_inventory.yml test_vxlan_large.yml --tags cr_manage_vrfs_networks

rr stands for remove_role

The following tags can be used to selectively execute stages within the cisco.nac_dc_vxlan.create role

# Selectively run stage to remove networks and vrfs and skip all other stages
ansible-playbook -i test_inventory.yml test_vxlan_large.yml --tags "rr_manage_networks, rr_manage_vrfs"

Role Level Tags:

The validate role will automatically run if tags role_create, role_deploy, role_remove are specified.

Note: The roles must be tagged in the top level playbook for these capabilities to work so we will need to update our example_repo to indicate this.

# This is the main entry point playbook for calling the various
# roles in this collection.
- hosts: nac-ndfc1
  any_errors_fatal: true
  gather_facts: no

  roles:
    # Prepare service model for all subsequent roles
    #
    - 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'

Example: Selectively Run cisco.nac_dc_vxlan.create role alone

ansible-playbook -i test_inventory.yml test_vxlan_large.yml --tags role_create

This update provides the following help at runtime if an invalid tag is specified

ansible-playbook -i test_inventory.yml test_vxlan_large.yml --tags bogus_tag    

PLAY [fabric_full_large] ********************************************************************************************************************************************************************************

TASK [cisco.nac_dc_vxlan.common_global : Verify User Tags] **********************************************************************************************************************************************
fatal: [fabric_full_large]: FAILED! => {"changed": false, "msg": "Tag 'bogus_tag' not found in list of supported tags", "supported_tags": ["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"]}

PLAY RECAP **********************************************************************************************************************************************************************************************
fabric_full_large          : ok=0    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0