This playbook is true infrastructure-as-code. Users declare a list of VRFs
under Ansible's control, then specify which route-targets should exist.
Any unspecified route-targets are automatically and idempotently removed.
Whenever changes occur, routing and ping reachability is validated.
Contact information:
Email: njrusmc@gmail.com
Twitter: @nickrusso42518
At present, only Cisco IOS platforms are supported. Cisco IOS-XR may
be added in the future.
Testing was conducted on the following platforms and versions:
$ cat /etc/redhat-release
Red Hat Enterprise Linux Server release 7.4 (Maipo)
$ uname -a
Linux ip-10-125-0-100.ec2.internal 3.10.0-693.el7.x86_64 #1 SMP
Thu Jul 6 19:56:57 EDT 2017 x86_64 x86_64 x86_64 GNU/Linux
$ ansible --version
ansible 2.8.7
config file = /home/ec2-user/racc/ansible.cfg
configured module search path = ['/home/ec2-user/.ansible/plugins/modules',
'/usr/share/ansible/plugins/modules']
ansible python module location =
/home/ec2-user/environments/racc287/lib/python3.7/site-packages/ansible
executable location = /home/ec2-user/environments/racc287/bin/ansible
python version = 3.7.3 (default, Aug 27 2019, 16:56:53)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-36)]
For each host (or group of hosts), a vrf
list is defined. This list of
dictionaries has the following format:
---
vrfs:
- name: "VRF1"
description: "first VRF"
rd: "65000:1"
route_import:
- "65000:1"
route_export:
- "65000:2"
check:
routes:
- "10.3.3.0/30"
- "10.4.4.0/24"
pings:
- "10.3.3.1"
- "10.4.4.44"
- name: "VRF2"
description: "second VRF"
rd: "65000:2"
route_import:
- "65000:1"
route_export:
- "65000:2"
check:
routes:
- "10.3.3.0/30"
- "10.4.4.0/24"
pings:
- "10.3.3.1"
- "10.4.4.44"
The individual components in each dictionary are as follows:
name
: The name of the VRF. Numbers can be used, but should be quoteddescription
: The description of the VRF.rd
: The BGP route distinguisher that makes all routes in this VRFroute_import
: The list of route target (RT) extended communities,route_export
: The list of route target (RT) extended communities,check
: Optional nested dictionary that helps with verification. Tofalse
.
routes
: List of prefixes in CIDR notation which should be presentpings
: List of single IP addreses which should be pinged fromroutes
key, but it does not have to be.The playbook begins by collecting the existing VRF configuration and parsing
it to retrieve the currently configured import and export RTs for all VRFs
on the router, even those not being managed by this playbook. Next, the
parsed RT information from the router is compared against the user-provided
intended RT configuration. For each user-defined VRF, the playbook determines
which RTs must be added or deleted. RTs absent from the intended RT
configuration are automatically and idempotently removed.
The playbook also configures VRFs in BGP and redistributes any connected
routes. If a user-defined VRF does not exist in the current configuration, it
is added, along with all defined RTs. If a VRF exists in the current
configuration but does not exist in the user-defined configuration, it is
ignored. This conservative behavior allows some VRFs to remain outside of
Ansible's control (for example, a management VRF).
If any changes were made, the system waits for a configurable amount of time,
with a default of 60 seconds. This allows the router to import new routes into
the VRF and affix new exported RTs. It also accounts for the time needed for
VRF FIBs to install their routes upon receipt from BGP. The system also
prints the changes made to stdout. When there are no changes, there is no
wait period and no stdout output.
Last, the routing and ping verification runs. These test cases are run
regardless of whether changes occurred or not.
Please see the outputs in the samples/
directory to see the playbook output.
This playbook comes with three test phases, executed in sequence:
pylint
package.black
package.do_ssh
which is skipped when these tests are run. MockTo simplify testing both for CI and for manual executions, a GNU Makefile
with phony targets is used. Use the following shortcuts to test the playbook.
It is recommend to run all tests immediately after cloning to save yourself
the pain of discovering bugs during development.
make lint
: Runs the linting processmake unit
: Runs the unit testsmake pb
: Runs the playbook testsmake test
: Runs all tests (linting, unit, and playbook, in that order)Please see .travis.yml
for more details on how the tests are executed.
This playbook is a true infrastructure-as-code. Users declare a list of VRFs under Ansible's control and specify which route-targets should exist. Any unspecified route-targets are automatically and idempotently removed. Whenever changes occur, routing and ping reachability is validated.
Code Exchange Community
Get help, share code, and collaborate with other developers in the Code Exchange community.View Community