0% found this document useful (0 votes)
68 views

Jinja2 Hands-On Exercises

Uploaded by

m
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
68 views

Jinja2 Hands-On Exercises

Uploaded by

m
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

JINJA2 HANDS-ON EXERCISES

For each exercise, create a Jinja2 document that will transform one of the
YAML documents you created in the previous set of exercises into a router
configuration. You can use the online Jinja parser to check the results.

1. Using a dictionary created in YAML exercise #1 that contains hostname,


loopback and banner, create the following router configuration. Skip the
banner configuration if the banner attribute is not defined.

hostname <hostname>
!
interface loopback 0
ip address <loopback> 255.255.255.255
!
banner motd #
<banner>
#

2. Using a dictionary created in YAML exercise #2 that contains hostname,


loopback, and interfaces (list of interface names), create the following
router configuration:

hostname <hostname>
!
interface loopback 0
ip address <loopback> 255.255.255.255
!
! for each interface
interface <interface name>
no shutdown

3. Using a list of hostnames created in YAML exercise #3 create Ansible


inventory file:

# for each host


#
<hostname> ansible_user=cisco ansible_ssh_pass=cisco

4. Using a list of username/password pairs created in YAML exercise #4


create a local user database for a Cisco IOS router:

! for every user


username <username> password <password>

© Copyright ipSpace.net 2017 Page 1

This material is copyrighted and licensed for the sole use by Mikel Maeso ([email protected] [85.87.178.33]). More information at http://www.ipSpace.net/Webinars
5. Using the list of users created in YAML exercise #5 create a local user
database for a Cisco IOS router. Use privilege level 2 for users without
privilege attribute.

! for every user


username <username> password <password>
username <username> privilege <privilege>
!
! for users with autocommand attribute
username <username> autocommand <autocommand>

6. Using the list of BGP neighbors created in YAML exercise #6 create Cisco
IOS BGP router configuration:

router bgp 64000

 For BGP neighbors with state = absent:

no neighbor <address>

 For all other BGP neighbors:

neighbor <address> remote-as <asn>


neighbor <address> description <description>
! only when policy attribute is present
neighbor <address> route-map <policy> in

 For BGP neighbors with state = down:

neighbor <address> shutdown

7. Create BGP neighbor configuration as above, adding prefix lists where


necessary:
 For every neighbor that has prefixes attribute

neighbor <address> prefix-list bgp-neighbor-<address> in

 Create a prefix list for every neighbor that has prefixes attribute.

! for every prefix in the list


ip prefix-list bgp-neighbor-<address> seq <count> permit <value>

© Copyright ipSpace.net 2017 Page 2

This material is copyrighted and licensed for the sole use by Mikel Maeso ([email protected] [85.87.178.33]). More information at http://www.ipSpace.net/Webinars
8. Create a BGP router configuration using YAML document created in YAML
exercise #8:
 Create common device configuration as in exercise 1
 Create BGP configuration as in exercise 7
 Create interfaces configuration:

! for every interface in the interfaces list


!
interface <name>
ip address <address>

9. [I]1 Using the following data model (source @


https://github.com/ipspace/MPLS-infrastructure/blob/master/fabric.yml)

---
node: E1
fabric:
- {left: E1, left_ip: 10.0.0.21, left_port: GigabitEthernet0/2,
right: E2, right_ip: 10.0.0.22, right_port: GigabitEthernet0/2,
cost: 5 }
- {left: E1, left_ip: 10.0.0.13, left_port: GigabitEthernet0/1,
right: PE1, right_ip: 10.0.0.14, right_port: GigabitEthernet0/1,
cost: 10 }
- {left: E2, left_ip: 10.0.0.17, left_port: GigabitEthernet0/1,
right: PE1, right_ip: 10.0.0.18, right_port: GigabitEthernet0/2,
cost: 1 }
- {left: E3, left_ip: 10.0.0.41, left_port: GigabitEthernet0/2,
right: E4, right_ip: 10.0.0.42, right_port: GigabitEthernet0/2 }
- {left: E3, left_ip: 10.0.0.29, left_port: GigabitEthernet0/3,
right: PE2, right_ip: 10.0.0.30, right_port: GigabitEthernet0/1 }
- {left: E4, left_ip: 10.0.0.37, left_port: GigabitEthernet0/3,
right: PE2, right_ip: 10.0.0.38, right_port: GigabitEthernet0/2 }

nodes:
- name: E1
mgmt: 172.16.1.110
rid: 192.168.0.2
- name: E2
mgmt: 172.16.2.1 255.255.255.240
rid: 192.168.0.4

1
This is an intermediately-hard exercise. You might want to solve it after getting
more hands-on Jinja2 practice.

© Copyright ipSpace.net 2017 Page 3

This material is copyrighted and licensed for the sole use by Mikel Maeso ([email protected] [85.87.178.33]). More information at http://www.ipSpace.net/Webinars
Create the router configuration for node specified in the node
attribute:

hostname <name>
interface loopback 0
ip address <rid> 255.255.255.255
!
interface GigabitEthernet0/0
ip address <mgmt> ! use mask 255.255.255.0 when mask is not specified
!
! for every fabric interface
interface <port>
ip address <ip> 255.255.255.252
no shutdown
ip ospf 1 area 0
!
router ospf 1
router-id <rid>

Use macros to generate fabric interface configuration.

© Copyright ipSpace.net 2017 Page 4

This material is copyrighted and licensed for the sole use by Mikel Maeso ([email protected] [85.87.178.33]). More information at http://www.ipSpace.net/Webinars

You might also like