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
orderIntegermin: 0, max: 9No0
fileStringNo
contentStringNo

Model templates define configuration inline using the standard data model structure. These are best for simple, self-contained configurations.

Example:

iosxr:
templates:
- name: ntp_template
type: model
configuration:
ntp:
update_calendar: true
log_internal_sync: true
source_interface_name: "GigabitEthernet0/0/0/0"
max_associations: 5
broadcastdelay: 10
ipv4_peers_servers:
- address: "192.168.1.100"
type: "server"
version: 4
key: 10
minpoll: 4
maxpoll: 6
prefer: true
iburst: true

File templates reference external .tftpl files that use Terraform templating syntax. These are ideal for complex configurations with dynamic content generation.

Template Definition:

iosxr:
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.

CLI templates support an optional order attribute (valid range: 0-9) to control the sequence in which templates are applied. Templates with lower order values are applied first. The default order is 0, meaning templates without an explicit order value are applied first. Templates with the same order value may be applied in parallel.

Note: CLI templates should be considered a last resort in case YANG models are not available. They cannot read state and therefore cannot reconcile changes (including delete operations).

Example:

iosxr:
templates:
- name: isis-metric
type: cli
order: 1
content: |
router isis P1
interface GigabitEthernet0/0/0/0
address-family ipv4 unicast
metric 10

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

iosxr:
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.

iosxr:
device_groups:
- name: CORE_ROUTERS
templates:
- ntp_template
- standard_cdp

Templates applied at the device level affect only that specific device, useful for device-specific configurations.

iosxr:
devices:
- name: router-1
host: 10.10.10.1
templates:
- core_routing

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