Skip to content
This repository has been archived by the owner on Jun 28, 2022. It is now read-only.

Run Phase

TiTom edited this page Nov 13, 2015 · 2 revisions

Build Phase

In this section, script will provide a way to update configuration on all devices running your lab. It is based on JINJA2 template engine and YAML datavars as well.

Build configuration offline

Script is available at this page

First of all, it is required to build a Jinja2 template. A Jinja2 is a common language to build template and it is not junos oriented. More information about how Jinja2 works is available at the following page. Below is an example of JINJA2 syntax in a Junos configuration:

interfaces {
    {%- for item in uplinks %}
    {{uplinks[item]['interface']}} {
        unit 0 {
        description "{{uplinks[item]['description']}}";
            family inet {
                address {{uplinks[item]['address']}}/31;
            }
        }
    }
    {%- endfor %}

Then you have to create your YAML file to specify a key values per device. Below is a quick overview of how a YAML file might be constructed:

 - host_name: leaf1
  management_ip: 172.30.108.139
  # loopback and router_id and ibgp (overlay/evpn) local_address are the same
  loopback: 10.20.1.1
  router_id: 10.20.1.1
  switch_options_route_distinguisher: 10.20.1.1:1
  snmp_location: "DC1 room1 raw1 rack01"
  uplinks: 
   to_spine01: 
    interface: et-0/0/22
    description: "UPLINK - L1 to S1 - 192.168.0.0/31"
    address: 192.168.0.0
   to_spine02: 
    interface: et-0/0/23
    description: "UPLINK - L1 to S2 - 192.168.0.2/31"
    address: 192.168.0.2
  • Usage:
python run-deploy-jinja-template.py -t $template-file$ -d $yaml-file$ -k $yaml-key$ -u $username$ -p $password$

In this scenario, YAML key is entry prefixes with - in your YAML file.

Script will parse YAML and will create a complete configuration file to push on device. As this script is a little bit critical by applying changes directly on devices, you have to specific options:

  • --verbose | -v: usefull to display result of a show|compare before a commit

  • --safe | -s: enable dry-run mode and make a rollback instead of committing your changes.

  • Output example:

Below is an example of script output:

 Start configuration building                         
   * Start updating 172.30.108.228                    
   * Connected to 172.30.108.228                      
     * Configuration Diff is :                        
                                                     
   [edit system]                                      
   -  host-name leaf01;                               
   +  host-name leaf01-automate;                      
   +  location {                                      
   +      building ESX01;                             
   +      floor 4;                                    
   +  }                                               
   [edit system name-server]                          
       8.8.4.4 { ... }                                
   +   10.73.2.253;                                   
   [edit snmp]                                        
   +  description leaf01-automate;                    
   -  location DC1;                                   
   +  location "AS73 Exchanger Network";              
   +  contact "[email protected]";                   
   +  community inetsix-ro {                          
   +      authorization read-only;                    
   +  }                                               
   +  trap-group space {                              
   +      targets {                                   
   +          10.1.1.9;                               
   +      }                                           
   +  }                                               
                                                     
     ** Running in dry-run mode, commit aborted       
                                                     
 End of Script  
Clone this wiki locally