Template
Templates provide a powerful way to define reusable configuration blocks that can be applied to multiple device groups or devices with different variable values. This is particularly useful for service-related configurations that need to be deployed repeatedly across different devices or environments with slight variations.
Templates support three different types:
model
: Configuration defined inline using the data model structurefile
: External template files (.tftpl
) using Terraform templating syntaxcli
: Raw CLI commands for features not available in the data model
Configuration templates work by:
- Defining templates once
- Referencing templates by name at the global, device group, or device level
- Using global, device group, or device-level variables to populate template parameters
- Applying templates in the order specified
This approach promotes configuration consistency, reduces duplication, and simplifies management of similar services across your network infrastructure.
Diagram
Section titled “Diagram”Classes
Section titled “Classes”templates (iosxe)
Section titled “templates (iosxe)”Name | Type | Constraint | Mandatory | Default Value |
---|---|---|---|---|
name | String | Yes | ||
type | Choice | model , file , cli | Yes | |
file | String | No | ||
content | String | No |
Template Types
Section titled “Template Types”Model Templates
Section titled “Model Templates”Model templates define configuration inline using the standard data model structure. These are best for simple, self-contained configurations.
Example:
iosxe: templates: - name: aaa_tacacs type: model configuration: aaa: new_model: true tacacs_groups: - name: ISE vrf: Mgmt-vrf server_names: [ise1, ise2] source_interface_type: Loopback source_interface_id: 0
File Templates
Section titled “File Templates”File templates reference external .tftpl
files that use Terraform templating syntax. These are ideal for complex configurations with dynamic content generation.
Template Definition:
iosxe: templates: - name: standard_vlans type: file file: templates/vlans.yaml.tftpl
Template File Content (templates/vlans.yaml.tftpl
):
vlan: vlans:%{ for vlan in site_vlans } - id: ${vlan.id} name: "${vlan.name}"%{ endfor }
Terraform Templating Syntax:
%{ }
- Control structures (for loops, if statements, etc.)${ }
- Variable interpolation~
- Whitespace stripping
CLI Templates
Section titled “CLI Templates”CLI templates contain raw CLI commands for features that are not available in the data model. These are applied directly to the device.
Example:
iosxe: templates: - name: qos_config type: cli content: | mls qos mls qos map cos-dscp 0 8 16 24 32 46 48 56
Template Application Levels
Section titled “Template Application Levels”Templates can be applied at three different levels, providing flexibility in how configuration is deployed:
Global Level
Section titled “Global Level”Templates applied at the global level are inherited by all device groups and devices (unless overridden).
iosxe: templates: - name: base_security type: model configuration: # ... configuration ...
# Apply to all devices global: templates: - base_security
Device Group Level
Section titled “Device Group Level”Templates applied at the device group level affect all devices in that group.
iosxe: device_groups: - name: ACCESS_SWITCHES templates: - aaa_tacacs - standard_vlans
Device Level
Section titled “Device Level”Templates applied at the device level affect only that specific device, useful for device-specific configurations.
iosxe: devices: - name: SW-CORE-01 url: "https://10.1.1.1" templates: - core_routing - hsrp_config
Template Precedence
Section titled “Template Precedence”Template Inheritance and Merging
Section titled “Template Inheritance and Merging”Templates are applied in the following order:
- Global templates
- Device group templates
- Device-specific templates
Templates at each level are merged with templates from previous levels, allowing you to build configurations incrementally.
Variable Precedence
Section titled “Variable Precedence”When templates are processed, variables are resolved in the following order (highest to lowest priority):
- Device-level variables
- Device group variables
- Global variables
Template Type Selection
Section titled “Template Type Selection”- Use model templates for straightforward configurations that map directly to the data model nad only require templating of values
- Use file templates for complex configurations with loops, conditionals, or dynamic structures
- Use cli templates as a last resort, only for features not yet supported in the data model