Network Continuous integration using Jenkins,Jinja2 and Ansible.

Started by burnyd, March 12, 2017, 06:02:20 AM

Previous topic - Next topic

burnyd

Network Continuous integration using Jenkins,Jinja2 and Ansible.

I have been into the devops and agile life lately.  I have read the following books that have been extremely technology changing for myself.. Devops 2.0 Ansible for Devops Learning Continuous integration with Jenkins The Devops 2.0 book is fantastic and @vfarcic constantly updates the book so it is worth the price of admission.  I have said this […]

I have been into the devops and agile life lately.  I have read the following books that have been extremely technology changing for myself..


Devops 2.0

Ansible for Devops

Learning Continuous integration with Jenkins


The Devops 2.0 book is fantastic and @vfarcic constantly updates the book so it is worth the price of admission.  I have said this many times before about Devops.  Devops is simply using open source tooling to run through a workflow in a automated fashion.  The definition of Continuous integration is constantly testing your code to integration into production.


We as network engineers commonly use CLI or manual tasks to put into production because we know what are doing will “Just work.”  We have done it a million times and it has never failed.  We do not take into account human error or issues within the process ie firewall rules, wrong ip address etc.


This is the devops way which should be implemented for anything new configuration wise following the devops practive.


devopslife


Script/configuration is implemented to Jenkins.  Jenkins schedules the task.  Ansible iterates upon the script.  Checks and balances are done.  The script/config is then ran on the switch.  This is another use case for docker on a switch as this could all be ran in a test container before trying the code on the actual switch.  Finally notifications of the test build being successful are sent out either through slack or through email.


So in this blog post we are going to do something really simple so any network engineer can follow along and get their feet wet into the continuous integration book.  I also highly recommend the three books in which I have posted above.


Our topology is simple

-2 Oracle Virtual BOX VM’s

1.) Ubuntu 14.04 LTS

2.) Arista vEOS running 4.16

-Jenkins is running on the Ubuntu VM

-Ansible is running on the Ubuntu VM

-Python 2.7 is running on the Ubuntu VM


I will start with a simple line of configuration.  NTP is probably the easiest 1 liner of configuration we as network people normally use.  An NTP server can be added to a switch with a 1 liner


ntp server 10.10.10.10


We are going to make this slightly fancy here with Ansible and Jinja templates as if we ever wanted to change our NTP server we could do it on a large amount of switches in a ansible inventory.  So here is the J2 template it is very simple.  Lets take a look at our Ansible structure first.

tree

group_vars – Will hold all the variables in this case the NTP server config.

veos.yaml – contains the ntp server

inventory – contains all the hosts within the inventory file.

ntpserver.yaml – The ansible playbook

scripts – optional directory this has a python script we will get to that later

templates – directory that holds Jinja2 templates

ntpserver.j2 – holds the configuration “ntp server x.x.x.x”


Lets first check out our ansible-playbook


ntpp

This ansible-playbook simply uses the veos hosts which are located in the inventory file.

The second step is uses the eos_template which is located in the templates/ntpserver.j2 and applies this NTP server to each host like a giant for loop.


veos.yaml

ntpserver

ntpserver.j2

ntpserverconfig.png


This would simply add a NTP server to a arista vEOS device as long as its in the .eapi file and in the inventory file.


So for those who are following so far the next step is running this through a CI integration.  That is where Jenkins comes through.  Jenkins can execute the playbook and run through its checks and balances.  Here this is extremely simple as we are not doing much.  The work flow is as follows once again..

devopslife


Here is the job we will run.

jenkins

Here is a example of the job.

job


The first step is to run the playbook and run it in  “–Check” Mode.  This will run the play book as a dry run and not make any changes.  This is simply for any sort of error corrections or something that would be wrong with trying to connect to something within the host file.  So if either switch did not connect.


The second step is to start the configuration.  This will apply the configuration on the switch as it is in the Jinja2 templates.


The last step is a Python script shown here.

python


Alright so enough typing lets go ahead and run the script and hit the console into JenkinsCI.

jenkinsci

We were able to run through the tests everything is successful. Checking the switch it shoes the new NTP server of 10.10.10.10.


Lets purposely fail this setup and try to make a NTP server of something bogus that the switch would never take.


failure


This time it failed.  The first dry run will work because it can connect.  The second execution will not run as it will simply fail at trying to add commands to the switch.

Typically at this point either a email or a chat notification is sent out to make the rest of the team aware.


This was a good exercise walking through CI of network changes.  This is for sure the way to go for testing and checking for network changes in live production.


 


 
Source: Network Continuous integration using Jenkins,Jinja2 and Ansible.

Dieselboy

Thanks so much for your post. I have been getting into ansible the past week. I plan to tackle a small task first, which is configure scheduled configuration backups and store them on Git. I've been using rancid for config backups and I can't get WLC or ASA config backup working through rancid.

I have windows 10 and I'm using ansible through the windows bash.exe shell.

Eventually I want to use for as much as I can for repeated tasks.

wintermute000

this is the bomb

http://shop.oreilly.com/product/0636920035626.do

move away from windows NOW for devops. Nothing but pain, even with bash shell. Wait till you try to chef it in windows. LOL


VM is perfectly fine if you don't want to change your sexuality aka get a macbook (I jest, I jest) or man up and go all-in on linux desktop


deanwebb

Take a baseball bat and trash all the routers, shout out "IT'S A NETWORK PROBLEM NOW, SUCKERS!" and then peel out of the parking lot in your Ferrari.
"The world could perish if people only worked on things that were easy to handle." -- Vladimir Savchenko
Вопросы есть? Вопросов нет! | BCEB: Belkin Certified Expert Baffler | "Plan B is Plan A with an element of panic." -- John Clarke
Accounting is architecture, remember that!
Air gaps are high-latency Internet connections.