Templates Presentation
Templates Presentation
Helpful Templates
Showcasing the value of Templates
with Real World Examples
Today’s
discussion
1 Why Real World Examples?
2 Template Examples
3 Resources
© 2024 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 2
Cisco Confidential
Why these real world examples?
• Real World examples that prove the value of Catalyst Center
• No other competitor (that I know of) uses programmatic principles and applies them to CLI
• Direct correlation to day-to-day tasks of Network Engineering teams
• Same things need to be configured on devices regardless of industry
• Credentials, other basic configs, VLANs, SVIs and ports, AAA, ACLs, QoS, etc…
• Programmatic template of a few lines can translate to CLI consisting of thousands of lines
• Incentive as well as means to standardize configs, while accounting for current lack of
standardization
• Reduces the possibility of human error when doing configs
• Simple templates that are easy to implement in either VTL or Jinja
• Most complicated template uses if/then/else statement
© 2024 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 3
Cisco Confidential
Basic Variables – Example 1
• Talking Point
• Basic substitution of a variable in a cli
• Useful for values that will change depending on device, i.e. IP address, port number, etc….
• int gig1/0/$access_port
• description Staff user port
• switchport access vlan 200
• switchport mode access
• switchport voice vlan 20
• spanning-tree portfast
• spanning-tree bpduguard enable
• spanning-tree guard root
© 2024 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 4
Cisco Confidential
Trigger Templates - Example 1
• Talking Point
• Run specific segments of code in a template or a specific template in a composite template
• Provides very granular control over what config is pushed to a device
• Useful in both Day-0 and Day-N templates
• #set($INTERFACE_TEMPLATE_RESPONSE = $RUN_INTERFACE_TEMPLATE)
• #if($INTERFACE_TEMPLATE_RESPONSE == "Yes")
• interface Vlan100
• ip address $User_VLAN_IP 255.255.255.0
• interface Vlan200
• ip address $Staff_VLAN_IP 255.255.255.0
• #else
• #end
© 2024 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 5
Cisco Confidential
Basic For Each Loops- Example 1
• Talking Point
• Useful for configuring a standardized range of ports
• Example: Pushing configs for access ports with multiple interface types
• #foreach($access_port in [${first-access-port}..${end-access-port}])
• int ${interface_type}1/0/$access_port
• description Staff user port
• switchport access vlan 200
• switchport mode access
• spanning-tree portfast
• spanning-tree bpduguard enable
• spanning-tree guard root
• #end
© 2024 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 6
Cisco Confidential
Multiple For Each Loops- Example 1
• Talking Point
• Useful for interfaces that need two different sets of configs, i.e. trunk ports, access ports, uplink ports, etc…
• #foreach($access_port in [${first-access-port}..${end-access-port}])
• int ${interface_type}1/0/$access_port
• description Staff user port
• switchport access vlan 200
• switchport mode access
• spanning-tree portfast
• spanning-tree bpduguard enable
• spanning-tree guard root
• #end
© 2024 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 7
Cisco Confidential
Multiple For Each Loops- Example 2
• Talking Point
• Useful for customers with switch stacks
• Example: Pushing configs for trunk and access ports w/ variable for stacks
• #foreach($trunk_port in [${first-trunk-port}..${end-trunk-port}])
• #foreach($stack_number in [${first-stack-number}..${end-stack-number}])
• int ${trunk_interface_type}${stack_number}/0/$trunk_port
• description Uplink port
• switchport mode trunk
• switchport trunk allowed vlan 20,100,200,300,400
• #end
• #end
•
• #foreach($access_port in [${first-access-port}..${end-access-port}])
• #foreach($stack_number in [${first-stack-number}..${end-stack-number}])
• int ${access_interface_type}${stack_number}/0/$access_port
• description Staff user port
• switchport access vlan 200
• switchport mode access
• spanning-tree portfast
• spanning-tree bpduguard enable
• spanning-tree guard root
• #end
• #end
© 2024 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 8
Cisco Confidential
Bind to Source - Example 1
• Talking Point
• Apply cli based on properties of device that DNA Center has ingested into database, i.e. interface name, host
name, etc…
© 2024 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 9
Cisco Confidential
Implict Variables - Example 1
• Talking Point
• Apply cli based on properties of device that DNA Center has ingested into database, i.e. interface name, host
name, etc…
• Can apply widespread change across range of devices regardless of model, i.e. make change to all access
and trunk ports
• Careful attention must be paid to logic to make exclusions, i.e. GigabitEhternet0 is considered a physical port
• Example: Use implicit variables to apply changes to all trunk and access ports
• #foreach ($interface in ${__interface})
• #if ($interface.portName.contains(“Bluetooth") || $interface.portName.contains("App") || $interface.portName.contains("GigabitEthernet0"))
• #elseif ($interface.interfaceType == "Physical" && $interface.portMode == "access")
• interface $interface.portName
• switchport access vlan 10
• switchport mode access
• switchport voice vlan 20
• spanning-tree portfast
• spanning-tree bpduguard enable
• spanning-tree guard root
• #elseif($MODEL.contains("3850"))
• interface GigabitEthernet1/0/1
• description 3850-L2 LAN PORT
• switchport mode access
• spanning-tree portfast
• no shut
• #else
• #end
•
© 2024 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 11
Cisco Confidential
Implict Variables - Example 3
• Talking Point
• Apply cli based on properties of device that DNA Center has ingested into database, i.e. interface name, host
name, etc…
• Can apply config based on properties of the device itself, i.e. Platform ID
© 2024 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 12
Cisco Confidential
Implict Variable Values - Interfaces
• Talking Point
• Template that shows the implicit variable values for interfaces that logic can be run on
© 2024 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 13
Cisco Confidential
Implict Variable Values - Interfaces
• pid: C9300-48P
• vlanId: 1
• ifIndex: 70
• adminStatus: UP
• mtu: 9100
• speed: 40000000
• macAddress: 6c:71:0d:22:20:be
• status: down
• portName: FortyGigabitEthernet1/1/2
• series: Cisco Catalyst 9300 Series Switches
• deviceId: f23e88dd-9e02-4d22-97c3-a54d52f49848
• networkdevice_id: 508506000
• ospfSupport: false
• portMode: dynamic_auto
• portType: Ethernet Port
• poweroverethernet: 0
• serialNo: FJC2341E0H6
• duplex: AutoNegotiate
• interfaceType: Physical
• isisSupport: false
• description: Uplink Port
© 2024 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 14
Cisco Confidential
Implict Variable Values - Devices
• Talking Point
• Template that shows the implicit variable values for devices that logic can be run on
© 2024 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 15
Cisco Confidential
Implict Variable Values - Devices
• apEthernetMacAddress:
• apManagerInterfaceIp:
• associatedWlcIp:
• description: Cisco IOS Software [Bengaluru], Catalyst L3 Switch Software (CAT9K_IOSXE), Version 17.6.5, RELEASE SOFTWARE (fc2) Technical
Support: http://www.cisco.com/techsupport Copyright (c) 1986-2023 by Cisco Systems, Inc. Compiled Wed 25-Jan-23 16:15 by mcpre
netconf enabled
• deviceSupportLevel: Supported
• family: Switches and Hubs
• hostname: FIAB.pod5css.cisco.com
• lineCardCount: 0
• macAddress: 6c:71:0d:22:20:80
• managementIpAddress: 172.16.6.97
• managementState: Managed
• platformId: C9300-48P
• reachabilityStatus: Reachable
• role: ACCESS
• roleSource: MANUAL
• serialNumber: FJC2341E0H6
• series: Cisco Catalyst 9300 Series Switches
• softwareType: IOS-XE
• softwareVersion: 17.6.5
• type: Cisco Catalyst 9300 Switch
• upTime: 244 days, 5:09:44.48
© 2024 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 16
Cisco Confidential
Resources
• Keith Baldwin’s Github Repository – https://github.com/kebaldwi?tab=repositories
• Examples of Velocity Templates - Arrays, For-Each-Loops, For-Each-Indexes, Macros, If/Else statements, Functions, Math -
https://thisbridgeistheroot.com/blog/dna-center-advanced-scripting
© 2024 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 17
Cisco Confidential