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.
Refer to: https://galaxy.ansible.com/ui/repo/published/cisco/dnac/content/module/template_workflow_manager/
- Create, update, or delete configuration templates.
- Apply templates to specific devices or device types.
- Manage template versions and rollback configurations.
- 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.
- Always refer to the detailed input specification for comprehensive information on available options and their structure.
- 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.
- 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: trueThe /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- 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! 👍
- 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- The config parameter within this task corresponds to the "Design > CLI Templates > Create Template" action in the Cisco Catalyst Center UI.
- Enter the parameters of the template you want to create.

- Enter content template -> Commit.

- Enter commit note -> Commit.

- Check template created.

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"
- Choose Template want to delete -> Delete.

- Click "Yes" to confirm deleting the template.

- Check Template deleted.

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"- Attach Template to Network Profile: Choose Template -> Attach.

- Choose the Network Profile to attach -> Save.

- Verify that the template was successfully attached.

- Choose Template deploy -> Provision Templates.

- Click Next.

- Choose device need deploy template.

- Click Next.

- Click Apply to deploy the template.

- 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"]
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
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]
- 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-
Provide workflow inputs in either inventory (
inventory/demo_lab/hosts.yaml) or the workflowvars/file. -
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