Guidelines for Configuration Template

#Substitution, Conditioning, and Looping in the Template should be in the Jinja2 standard. For more tutorials, refer to http://jinja.pocoo.org/docs/2.10/.

Points to Remember

Always enclose the commands within {% %} for "if," and "for," and "while" conditional statements

Always enclose the variables inside {{ }} for substitution

Sample Template Configuration

Example 1: Create an Empty List, add values to the List, and DO a simple ‘For Loop’

# Declaring a string variable to store value from Runtime or user. The default (“”) function will make the variable empty string till the USER input

{% set myinput = Runtime.interface_list | default(“”) %}

# Converting User Input to a list using the Split function

{% set mylist = myinput .split(",") %}

#Doing for Loop or Looping of Each Item

{% for each_interface in mylist %}
      <command prompt="#">int {{each_interface}}</command>
      <command prompt="#">shutdown</command>

# for requires endfor to close the section

{% endfor %}

Example 2: Conditions (if case elif Case and else case)

Example 3: Taking List Input from a Trigger

#down_interface_list_cisco_ios is a Trigger in Configuration Trigger

Example 4: Disable the Interface named ‘Ether’

# String Manipulation startswith, endswith, find, lower, upper, strip

Example 5: Taking the First Element from the Trigger

Last updated

Was this helpful?