Support Support Downloads Knowledge Base Juniper Support Portal Community

Knowledge Base

Search our Knowledge Base sites to find answers to your questions.

Ask All Knowledge Base Sites All Knowledge Base Sites JunosE Defect (KA)Knowledge BaseSecurity AdvisoriesTechnical BulletinsTechnotes Sign in to display secure content and recently viewed articles

How to use Jinja2 template automatically configure BGP on multiple logical-systems across multiple devices

0

0

Article ID: KB37551 KB Last Updated: 06 Oct 2021Version: 1.0
Summary:

This article describes how to configure multiple devices using a Jinja template configuration and Ansible playbook to avoid manually configuring each device separately.

Symptoms:

Manually configuring each device in a large topology can be a cumbersome, time-consuming an error-prone process requiring a separate login to each device. 

Cause:

Example with set up lab environment containing 3 logical systems on 3 routers each:

  1. lr1, lr2 lr3 exist on r1
  2. lr4, lr5, lr6 exist on r2
  3. l7, lr8, lr9 exist on r3

The logical-system "lr3" will serve as a route reflector. The following example configuration on "lr1" will stay the same for the remaining 7 logical systems, except for the local-address.

set logical-systems lr1 protocols bgp group pe type internal
set logical-systems lr1 protocols bgp group pe export nhs
set logical-systems lr1 protocols bgp group pe neighbor 192.168.0.3 local-address 192.168.0.1
set logical-systems lr1 protocols bgp group pe neighbor 192.168.0.3 family inet unicast
set logical-systems lr1 protocols bgp group pe neighbor 192.168.0.3 family inet-vpn unicast
set logical-systems lr1 protocols bgp group pe neighbor 192.168.0.3 family inet6 labeled-unicast explicit-null
set logical-systems lr1 protocols bgp group pe neighbor 192.168.0.3 family l2vpn signaling
set logical-systems lr1 protocols bgp group pe neighbor 192.168.0.3 family evpn signaling
set logical-systems lr1 protocols bgp group pe neighbor 192.168.0.3 family inet-mvpn signaling

 
Solution:

By generating a Jinja2 configuration template, repetitive configuration tasks across multiple devices can be automated. For example, in the above case you could use a Jinja2 configuration template to automatically build BGP configuration files, which could be applied using an Ansilbe playbook. All of this can be done without logging into a single router. The following snippet from the Jinja2 template shows how to place the variables and loop through the logical systems:


The following example host variable file from R2 shows how the variables are defined:

The same concept can be extended to reduce repetitive configuration tasks such as configuring MPLS, IS-IS, interfaces and other services separately.
Identify a common template and variables within the template which could be modified to automatically build configuration files suited for all devices (or logical systems in this case).
The following steps are required:

  1. Build the Jinja 2 configuration template and replace the variables with identifiers.
  2. Build inventory files specifying the IP addresses/host-names of all devices (i.e. r1, r2, r3 in this case)
  3. Build the variable files for each host, which includes the names of logical-systems in each device and assign the variable values for each logical-system.
  4. Build the Ansible playbook to automate the tasks of creating and applying configurations.
  5. Arrange all relevant files correctly in proper directory structure as show in the dry run below.
  6. Run the Ansible playbook from the Ansible host server.


To start, copy the project files from the following GitHub location:

Gather the project files from the Github location " https://github.com/pranavs2508/apply-bgp-configuration"

Or

Use "git clone https://github.com/pranavs2508/apply-bgp-configuration" on your Linux terminal.

 Example:

 

Verify BGP sessions:

Related Links

Comment on this article > Affected Products Browse the Knowledge Base for more articles related to these product categories. Select a category to begin.

Getting Up and Running with Junos

Getting Up and Running with Junos Security Alerts and Vulnerabilities Product Alerts and Software Release Notices Problem Report (PR) Search Tool EOL Notices and Bulletins JTAC User Guide Customer Care User Guide Pathfinder SRX High Availability Configurator SRX VPN Configurator Training Courses and Videos End User Licence Agreement Global Search