Jason Edelman's Blog
  • Home
  • About
  • Contact

Network Test Automation with Ansible

3/29/2014

5 Comments

 
In the last post, I talked about how Ansible could be used for various forms of network automation.  In the comments, Michael asked if Ansible could also be used for network test automation and verification.  Since I’m just starting to explore Ansible, I figured why not try it out.  The short answer is, it’s possible.  Let’s take a look at an example proving this out.
I just built a playbook that verifies a router, or group of routers, has reachability to a defined list of destinations.  Maybe you are deploying a new site? Maybe a new host?  Is the route being sent correctly to all sites?  Now, a playbook like this can be used to ensure every site (from the router) has reachability to the new site, subnet, or host.  You define the destination.  Cool, right?

Update: Before reading anymore, it's recommended to read the first post on Ansible for Networking.

Let’s do a quick walk through.

Here is the playbook.
Picture
As you can see, there is not a lot to it.  This playbook that we are looking at, called ‘pinger’, is using a module called ‘auto_pinger’.  Two variables get sent to auto_pinger: the first is the source_host, which is just the router that will be issuing the pings.  If you recall from the previous post, ‘inventory_hostname’ is just the name for the host located in the ‘hosts’ file.  

Now, how many devices and which devices, do you want to test reachability to?  remote_hosts is the directory where a file is located that has a list of these devices.  It’s that simple.

The task in the play in the playbook just states that each host in the group ‘routers’ is going to test connectivity to each host/destination defined in the file ‘remote_devices’ located in the ‘remote_hosts’ directory.  Note: file name must be called "remote_devices" for the destinations.  The path can be changed as a variable.

Let’s run the playbook.
Picture
The test is run.  What just happened? How do we view the results?  Did the pings pass or fail?  Well, the good news is that the tasks were “OK.” This means for us that the playbook succeeded (pings were sent from the devices), but again, what are the results?

To document the results, log files for each device are created.  I actually create two log files per device.  One  detailed log file per device that captures more information than the normal user would want to see and then a simple log file.  I’m only going to review the simple log file. 

Here are the contents of log_simple_router1 after running the playbook:

Picture
Note: cpal is being used on the backend for connecting to the network devices.


And by the way, it took this playbook just under 20 seconds to run.  If I wanted, I can probably get that down by a few seconds too.  How long does it take today if you want to test reachability to 4 destinations from 3 routers and write down the results?  Multiple that by 10, 20, or 100!

We can easily see the results in the simple log file for each ping test.  Since I hadn’t shown the remote devices file yet, you can see that I have four devices being tested for reachability.  I am testing reachability between all of the routers and then also to google showing there is internet access.  And for those who would rather see the output in excel or a different format, that’s possible too.  Just means some changes to the module.

Running this playbook also produced log_simple_router2 and log_simple_router3.  Those logs files aren’t shown here.

As an alternative and also helpful for debugging, it is possible to run a playbook with a ‘-v’ option to see the data being returned.  Here is the output of that:

Picture
The results being returned are in a dictionary and within the dictionary are various variables and other data types.  Again, this data can be used to troubleshoot or it can be gathered to use in other tasks further down in the playbook.  So, let’s say all 5 pings fail.  Maybe after that, you want to re-run the ping test again to prove the remote device is definitely unreachable.  After proving it is unreachable, it would then be possible to check the routing table of the router, do a traceroute, etc.  Liking this so far?

The user of the playbook, likely a network engineer, would only have to modify the ‘hosts’ file and ‘remote_devices’ file.  That is it.  No hardcore programming at all! 

It wouldn't be complete without showing the hosts and remote_device files.

hosts file:
Picture
remote_devices file:
Picture
The area of dynamic and automating testing is an interesting area and it may be one of those areas like automating the building of config files, where the proper tools and processes can be tested before starting to automate production devices.  

When you reboot a core switch, how many pings do you do to ensure everything is back up?  Stop that now!

With enough network centric Ansible modules, Ansible just may be the tool to help us network folk forward.

What do you think?  Would love to hear your thoughts.

Thanks,
Jason

PS – The playbook, files, and more are posted online.  Feel to take a look.

5 Comments
Steven Iveson
3/29/2014 12:40:49 pm

More awesome. I'd like to see some output around the sources and destinations before the results (ok or not) or as part of them. Perhaps split results by internal/WAN and internet. Anyway, great stuff that Anyone can modify and/or build upon.

Reply
Jason Edelman link
3/30/2014 03:32:03 pm

I think I know what you are saying, but that's why I showed the output with the '-v' option. The details returned back with the -v option could be tailored to meet your specific requirements.

Reply
Michael
3/30/2014 02:18:53 pm

Hi Jason,
thanks for taking interest in my comments. this looks very neat. the only downside is CPAL availability/support on the devices. But definitely a lot easier than writing 200 lines of java code. Hopefully, as time goes, more and more devices will support these APIs.

Reply
Jason Edelman link
3/30/2014 03:36:10 pm

No problem. You're right, that is the downside. However, the goal was really just to prove it out. I thought about using standard SSH for this, but it saved me a lot of time using CPAL since the module was already built out. Once legacy device support is added into CPAL, the option will be there for either (and other APIs)!

Reply
Christophe Useinovic
4/17/2014 09:34:17 pm

Hi !
Great job guys !
I would know how create the log file ? it's automatically generate ?
Thanks

Reply



Leave a Reply.

    Author

    Jason Edelman, Founder & CTO of Network to Code. 


    Enter your email address:

    Delivered by FeedBurner


    RSS Feed


    Categories

    All
    1cloudroad
    2011
    2960
    40gbe
    7000
    Arista
    Aruba
    Big Switch
    Brocade
    Capwap
    Christmas
    Cisco
    Controller
    Data Center
    Dell Force10
    Embrane
    Extreme
    Fex
    Hadoop
    Hp
    Ibm
    Isr G2
    Juniper
    Limited Lifetime Warranty
    Meraki
    Multicast
    N7k
    Nexus
    Nicira
    Ons
    Opendaylight
    Openflow
    Openstack
    Presidio
    Qsfp
    Quick Facts
    Routeflow
    Sdn
    Sdn Ecosystem
    Security
    Ucs


    Archives

    May 2015
    April 2015
    February 2015
    January 2015
    December 2014
    November 2014
    October 2014
    September 2014
    August 2014
    June 2014
    May 2014
    March 2014
    February 2014
    January 2014
    December 2013
    November 2013
    October 2013
    September 2013
    August 2013
    July 2013
    June 2013
    May 2013
    April 2013
    March 2013
    February 2013
    January 2013
    December 2012
    November 2012
    October 2012
    June 2012
    May 2012
    April 2012
    March 2012
    February 2012
    January 2012
    December 2011
    November 2011


    View my profile on LinkedIn
Photo used under Creative Commons from NASA Goddard Photo and Video