Sample Templates

Samples for Template Configuration.

  1. Create an Empty List and add values into List and DO a simple 'For Loop'.
  2. Conditions (if case elif Case and else case).
  3. Taking List Input from a Trigger.
  4. Disable the Interface named ‘Ether.’
  5. Taking First Element from the Trigger.
Example 1: Create an Empty List and add values into List and DO a simple ‘For Loop’.
                # Declaring a string variable to store value from Runtime or user.  
                Default (“”) function will make variable empty string till USER input: 
                  {%    set myinput = Runtime.interface_list | default(“”)   %}

                # Converting User Input to a list using Split function
                {%  set mylist = myinput .split(",")  %}

                # Doing for Loop or Looping of Each Item
                 i{% 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).
                {%  for each_interface in mylist  %}
                {% if each_interface == "Gi0/1"  %}
                  <command prompt="#">int {{each_interface}}</command>
                  <command prompt="#">shutdown</command>
                {% elif each_interface == "Gi0/2"  %}
                  <command prompt="#">int {{each_interface}}</command>
                  <command prompt="#">no shutdown</command>
                {% else %}
                  <command prompt="#">I dont know</command>
                {% endif %}
                {% endfor %}
              
Example 3: Taking List Input from a Trigger.
#down_interface_list_cisco_ios is a Trigger in Configuration Trigger.
 
                {%  set mylist1 = Trigger.down_interface_list_cisco_ios | default([])   %}
                  {% for each_interface in mylist1 %}
                        <command prompt="#">int {{each_interface}}<
                        <command prompt="#">shutdown</command>
                  {% endfor %}
              
Example 4: Disable the Interface named ‘Ether’.
# String Manipulation - startswith, endswith, find, lower, upper, strip.
                {% set myinput = Runtime.InterfaceNames | default ("") %}
                {% set mylist = myinput.split(",")  %}

                {%   for each_item  in  mylist  %}
                    {%  if each_item.lower().startswith("ether")    %}  
                     <command prompt="#">int {{each_item}}</command>
                     <command prompt="#">shutdown</command>
                    {% endif %}
                {% endfor %}
              
Example 5: Taking First Element from the Trigger.
                {% set mylist = Trigger.down_interface_list_cisco_ios | default ([])  %}
                {% if mylist  %}
                  <command timeout ="10" prompt ="#" >config t</command>  
                  <command timeout ="10" prompt ="#" >interface {{mylist[0]}}</command>
                  <command timeout="10" prompt ="#" >IP address 172.17.230.2 255.255.255.252</command>
                  <command timeout ="10" prompt ="#" >no shut</command>
                {% endif %}