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
- Identify specific feature configuration for two Spine or Leaf switches
- Identify switch specific configuration
- Write Jinja2 Template with variables for switch specific configuration
- 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 aggregated-ether-options lacp enable true
|
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:
Mani Subramanian is Senior Technical Product Manager for Pica8.