Blog

Automating Configuration For Group Of Switches Using Jinja2 Templates

 

One of the core functions of network automation is the ability to generate network device configurations from a template. The term template describes any sort of mold or pattern from which new, identical objects can be created. There are several templating languages that might suit our purposes, but the de facto standard when it comes to network configurations is Jinja2. Jinja is a simple yet powerful language which allows for the use of advanced logic to render documents.

Steps To Develop And Deploy Jinja2 Template

  1. Identify specific feature configuration for two Spine or Leaf switches
  2. Identify switch specific configuration
  3. Write Jinja2 Template with variables for switch specific configuration
  4. Automate configuration for group of switches using Jinja2 Template in AmpCon with Context Data (value for variables)

The MLAG configuration used in the Spine-01 and Spine-02 PicOS-V switches are given below.

Let us say we need to automate configuration of MLAG Feature in group of PicOS-V Spine switches (Spine-01 and Spine-02) represented in the following topology:

 

Step 1: Identify Configuration For Two Spine Switches

Spine-01 PicOS-V Switch Configuration

Spine-02 PicOS-V Switch Configuration

set interface aggregate-ethernet ae1 aggregated-ether-options lacp enable true
set interface aggregate-ethernet ae1 family ethernet-switching port-mode “trunk”
set interface aggregate-ethernet ae1 family ethernet-switching vlan members 15
set interface aggregate-ethernet ae1 family ethernet-switching vlan members 16
set interface aggregate-ethernet ae2 family ethernet-switching native-vlan-id 4088
set interface aggregate-ethernet ae2 family ethernet-switching port-mode “trunk”
set interface aggregate-ethernet ae2 family ethernet-switching vlan members 15
set interface aggregate-ethernet ae2 family ethernet-switching vlan members 16
set interface gigabit-ethernet te-1/1/1 ether-options 802.3ad “ae2”
set interface gigabit-ethernet te-1/1/2 ether-options 802.3ad “ae2”
set interface gigabit-ethernet te-1/1/3 ether-options 802.3ad “ae1”
set interface gigabit-ethernet te-1/1/4 family ethernet-switching native-vlan-id 15
set ip routing enable true
set l3-interface vlan-interface vlan4088 address 10.10.0.1 prefix-length 24
set protocols lldp enable true
set protocols mlag domain 10 node 0
set protocols mlag domain 10 peer-ip 10.10.0.2 peer-link “ae2”
set protocols mlag domain 10 peer-ip 10.10.0.2 peer-vlan 4088
set protocols mlag domain 10 interface ae1 link 1
set system hostname “spine-01”
set vlans vlan-id 15
set vlans vlan-id 16
set vlans vlan-id 4088 l3-interface “vlan4088”

set interface aggregate-ethernet ae1 aggregated-ether-options lacp enable true
set interface aggregate-ethernet ae1 family ethernet-switching port-mode “trunk”
set interface aggregate-ethernet ae1 family ethernet-switching vlan members 15
set interface aggregate-ethernet ae1 family ethernet-switching vlan members 16
set interface aggregate-ethernet ae2 family ethernet-switching native-vlan-id 4088
set interface aggregate-ethernet ae2 family ethernet-switching port-mode “trunk”
set interface aggregate-ethernet ae2 family ethernet-switching vlan members 15
set interface aggregate-ethernet ae2 family ethernet-switching vlan members 16
set interface gigabit-ethernet te-1/1/1 ether-options 802.3ad “ae2”
set interface gigabit-ethernet te-1/1/2 ether-options 802.3ad “ae2”
set interface gigabit-ethernet te-1/1/3 ether-options 802.3ad “ae1”


set ip routing enable true
set l3-interface vlan-interface vlan4088 address 10.10.0.2 prefix-length 24
set protocols lldp enable true
set protocols mlag domain 10 node 1
set protocols mlag domain 10 peer-ip 10.10.0.1 peer-link “ae2”
set protocols mlag domain 10 peer-ip 10.10.0.1 peer-vlan 4088
set protocols mlag domain 10 interface ae1 link 1
set system hostname “spine-02”
set vlans vlan-id 15
set vlans vlan-id 16
set vlans vlan-id 4088 l3-interface “vlan4088”

 

Step 2: Identify Switch Specific Configuration

When you compare the above two switches MLAG configuration, you will find most of the configuration lines are the same between the spine switches. Only a few lines of configuration vary between both switches, and are easy to identify.

Reference the highlights in the above step. The differing variables in each context data are summarized in the table below:

Variable Name Context Data Value For Spine-01 Switch Context Data Value For Spine-02 Switch
hostname spine-01 spine-02
my_mlag_node_num 0 1
my_mlag_ip 10.10.0.1 10.10.0.2
my_mlag_peer_ip 10.10.0.2 10.10.0.1

 

Step 3: Write Jinja2 Template With Variables.

The top portion of the Jinja2 template consists of configuration lines with variables. Jinja2 uses double curly braces to signify variables. The bottom portion of the Jinja2 Template has variables definition (Context Data).

Please refer to the Appendix A – Jinja2 Template to Configure MLAG in Spine PicOS-V Switches section in Using AmpCon to Manage PicOS-V Switches – Evaluation Guide.

 

Step 4: Automate Configuration For Group Of Switches Using Jinja2 Template In AmpCon.

For more details please refer to Automate Configuration of MLAG Feature in PicOS-V Switches section in Using AmpCon to Manage PicOS-V Switches – Evaluation Guide. You can also refer to the Video Guide:

Pica8 Network Platform Button
Pica8 Page Separator-1

manis

Mani Subramanian is Senior Technical Product Manager for Pica8.

 

Tagged automation, ampcon, PicOS-V, Jinja2