Skip to content

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 structure
  • file: External template files (.tftpl) using Terraform templating syntax
  • cli: 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
NameTypeConstraintMandatoryDefault Value
nameStringYes
typeChoicemodel, file, cliYes
fileStringNo
contentStringNo

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 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 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

Templates can be applied at three different levels, providing flexibility in how configuration is deployed:

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

Templates applied at the device group level affect all devices in that group.

iosxe:
device_groups:
- name: ACCESS_SWITCHES
templates:
- aaa_tacacs
- standard_vlans

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

Templates are applied in the following order:

  1. Global templates
  2. Device group templates
  3. Device-specific templates

Templates at each level are merged with templates from previous levels, allowing you to build configurations incrementally.

When templates are processed, variables are resolved in the following order (highest to lowest priority):

  1. Device-level variables
  2. Device group variables
  3. Global variables
  • 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