Skip to content

Latest commit

 

History

History
340 lines (294 loc) · 11.7 KB

File metadata and controls

340 lines (294 loc) · 11.7 KB

Ansible Workflow: Device Template Workflow Manager

I. Overview.

This Ansible workflow automates creating and managing template projects, device templates and deploying the templates to the devices. One of the many powerful features of Cisco's Catalyst Center is its templating engine, which allows you to configure nearly your entire network.

1. Detailed Input Spec.

Refer to: https://galaxy.ansible.com/ui/repo/published/cisco/dnac/content/module/template_workflow_manager/

2. Features.

  • Create, update, or delete configuration templates.
  • Apply templates to specific devices or device types.
  • Manage template versions and rollback configurations.

3. Main Task.

  • Manage operations such as creating, updating, and deleting configuration templates.
  • API to create a template by project name and template name.
  • API to update a template by template name and project name.
  • API to delete a template by template name and project name.
  • API to export the projects for given projectNames.
  • API to export the templates for given templateIds.
  • API to manage operation create of the resource Configuration Template Import Project.
  • API to manage operation create of the resource Configuration Template Import Template.
  • Deploy Templates to devices with device specific parameters.

4. Important Notes.

  • Always refer to the detailed input specification for comprehensive information on available options and their structure.

II. Procedure

1. Prepare your Ansible environment.

  • install Ansible if you haven't already
  • Ensure you have network connectivity to your Catalyst Center instance.
  • Checkout the project and playbooks: git@github.com:cisco-en-programmability/catalyst-center-ansible-iac.git.

2. Configure Host Inventory.

  • The host_inventory_dnac1/hosts.yml file specifies the connection details (IP address, credentials, etc.) for your Catalyst Center instance.
  • Make sure the catalystcenter_version in this file matches your actual Catalyst Center version.
  • The Sample host_inventory_dnac1/hosts.yml
---
catalyst_center_hosts:
    hosts:
        catalyst_center220:
            #(Mandatory) CatC Ip address
            catalyst_center_host:  <CatC IP Address>
            #(Mandatory) CatC UI admin Password
            catalyst_center_password: <CatC UI admin Password>
            catalyst_center_port: 443
            catalyst_center_timeout: 60
            #(Mandatory) CatC UI admin username
            catalyst_center_username: <CatC UI admin username> 
            catalyst_center_verify: false
            #(Mandatory) CatC Release version
            catalyst_center_version: <CatC Release version>
            catalyst_center_debug: true
            catalyst_center_log_level: INFO
            catalyst_center_log: true

3. Define Playbook input:

The /vars/template_workflow_inputs.yml file stores the sites details you want to configure.

  • Create templates
template_details:
  # List of templates to be uploaded to the Cisco Catalyst Center
  - configuration_templates:
      author: Pawan Singh
      composite: false
      custom_params_order: true
      template_description: Template to configure Access Vlan n Access Interfaces
      device_types:
        - product_family: Switches and Hubs
          product_series: Cisco Catalyst 9300 Series Switches
      failure_policy: ABORT_TARGET_ON_ERROR
      language: VELOCITY
      template_name: PnP-Upstream-SW
      project_name: access_van_template_9300_switches
      project_description: This project contains all the templates for Access Switches
      software_type: IOS-XE
      software_version: null
      template_content: |
        vlan $vlan
        interface $interface
        switchport access vlan $vlan
        switchport mode access
        description $interface_description
      version: "1.0"

  - configuration_templates:
      template_name: PnP-Upstream-SW1
      project_name: Onboarding Configuration
      template_tag: []
      author: admin
      device_types:
        - product_family: Switches and Hubs
          product_series: Cisco Catalyst 9500 Series Switches
        - product_family: Switches and Hubs
          product_series: Cisco Catalyst 9300 Series Switches
      software_type: IOS-XE
      language: VELOCITY
      template_content: |
        vlan $vlan
        interface $interface
        switchport access vlan $vlan
        switchport mode access
        description $interface_description
  • Deploy templates
template_details:
  - deploy_template:
      project_name: access_van_template_9300_switches
      template_name: PnP-Upstream-SW
      force_push: false
      template_parameters:
        - param_name: "vlan"
          param_value: "60"
        - param_name: "interface"
          param_value: "GigabitEthernet1/0/2"
        - param_name: "interface_description"
          param_value: "Upstream Interface Dummy"
      device_details:
        device_ips: 
          - 204.101.16.2

4. How to Validate Input.

  • Use yaml:
yamale -s workflows/device_templates/schema/template_workflow_schema.yml workflows/device_templates/vars/template_workflow_inputs.yml 
Validating /Users/pawansi/dnac_ansible_workflows/workflows/device_templates/vars/template_workflow_inputs.yml...
Validation success! 👍

5. How to Run.

  • Execute the Ansible Playbook to add, update, provision devices.
    ansible-playbook -i inventory/demo_lab/hosts.yaml workflows/device_templates/playbook/template_workflow_playbook.yml --e VARS_FILE_PATH=../vars/template_workflow_inputs.yml
  • How to Delete Existing Devices from inventory.
  • Run the Delete Playbook:
    ansible-playbook -i inventory/demo_lab/hosts.yaml workflows/device_templates/playbook/delete_template_workflow_playbook.yml --e VARS_FILE_PATH=../vars/delete_template_workflow_inputs.yml

III. Detailed steps to perform.

1. Create Templates - PnP-Upstream-SW.

Mapping config to UI Actions

  • The config parameter within this task corresponds to the "Design > CLI Templates > Create Template" action in the Cisco Catalyst Center UI.

alt text

  • Enter the parameters of the template you want to create. alt text
  • Enter content template -> Commit. alt text
  • Enter commit note -> Commit. alt text
  • Check template created. alt text

Example Input File

template_details:
  # List of templates to be uploaded to the Cisco Catalyst Center
  - configuration_templates:
      author: Pawan Singh
      composite: false
      custom_params_order: true
      template_description: Template to configure Access Vlan n Access Interfaces
      device_types:
      - product_family: Switches and Hubs
        product_series: Cisco Catalyst 9300 Series Switches
        #product_type: Cisco Catalyst 9300 Switch
      failure_policy: ABORT_TARGET_ON_ERROR
      language: VELOCITY
      project_name: access_van_template_9300_switches
      project_description: This project contains all the templates for Access Switches
      software_type: IOS-XE
      software_version: null
      template_name: PnP-Upstream-SW
      #tags:
      #  name: string
      template_content: |
        vlan $vlan
        interface $interface
        switchport access vlan $vlan
        switchport mode access
        description $interface_description
      version: "1.0"

2. Delete Templates

Mapping config to UI Actions

  • Choose Template want to delete -> Delete. alt text
  • Click "Yes" to confirm deleting the template. alt text
  • Check Template deleted. alt text

Example Input File

template_details:
  # List of templates to be uploaded to the Cisco Catalyst Center
  - configuration_templates:
      author: Pawan Singh
      composite: false
      custom_params_order: true
      template_description: Template to configure Access Vlan n Access Interfaces
      device_types:
      - product_family: Switches and Hubs
        product_series: Cisco Catalyst 9300 Series Switches
        #product_type: Cisco Catalyst 9300 Switch
      failure_policy: ABORT_TARGET_ON_ERROR
      language: VELOCITY
      project_name: access_van_template_9300_switches
      project_description: This project contains all the templates for Access Switches
      software_type: IOS-XE
      software_version: null
      template_name: PnP-Upstream-SW
      #tags:
      #  name: string
      template_content: |
        vlan $vlan
        interface $interface
        switchport access vlan $vlan
        switchport mode access
        description $interface_description
      version: "1.0"

3. Deploy Templates

Mapping config to UI Actions

  • Attach Template to Network Profile: Choose Template -> Attach. alt text
  • Choose the Network Profile to attach -> Save. alt text
  • Verify that the template was successfully attached. alt text
  • Choose Template deploy -> Provision Templates. alt text
  • Click Next. alt text
  • Choose device need deploy template. alt text
  • Click Next. alt text
  • Click Apply to deploy the template. alt text

Example Input File

- deploy_template:
    - project_name: Onboarding Configuration
      template_name: PnP-Upstream-SW
      force_push: true
      template_parameters:
        - param_name: "vlan_id"
          param_value: "1431"
      site_provisioning_details:
        - site_name: "Global/Bangalore/Building14/Floor1"
          device_family: "Switches and Hubs"
  - deploy_template:
    - project_name: Onboarding Configuration
      template_name: PnP-Upstream-SW
      force_push: true
      template_parameters:
        - param_name: "vlan_id"
          param_value: "1431"
      device_details:
        device_ips: ["10.1.2.1", "10.2.3.4"]

IV. References:

Note: The environment is used for the references in the above instructions.


  catalystcentersdk: 2.8.3
  cisco.catalystcenter: 2.6.0

Cisco Catalyst Center Ansible Module Documentation: template_workflow_manager

GitHub Source Code: template_workflow_manager.py

Workflow Steps

User Flow (3 Steps)

flowchart TD
  A[Start] --> B[Step 1: Create virtual env and install dependencies]
  B --> C[Step 2: Provide workflow inputs]
  C --> D{Choose input location}
  D -->|Option A| E[Update inventory hosts.yaml]
  D -->|Option B| F[Update vars input file]
  E --> G[Step 3: Export env vars]
  F --> G
  G --> H[Run ansible-playbook]
  H --> I[Review playbook summary output]
  I --> J[Done]
Loading

Installation and Run (Aligned)

  1. Create and activate a Python virtual environment, then install dependencies.
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
ansible-galaxy collection install cisco.catalystcenter --force
  1. Provide workflow inputs in either inventory (inventory/demo_lab/hosts.yaml) or the workflow vars/ file.

  2. Export Catalyst Center environment variables and run the playbook.

export HOSTIP=<catalyst-center-ip-or-fqdn>
export CATALYST_CENTER_USERNAME=<username>
export CATALYST_CENTER_PASSWORD='<password>'
ansible-playbook -i ./inventory/demo_lab/hosts.yaml ./workflows/device_templates/playbook/template_workflow_playbook.yml -vvvv