Creating and deleting VLANs on Cisco IOS using SNMP from Ansible

319 views
Skip to first unread message

Patrick Ogenstad

unread,
Feb 26, 2015, 1:07:21 PM2/26/15
to networ...@googlegroups.com
Hi,

I've previously created a module for Ansible which reads information from a device and lets you use them as facts in other modules. When I wrote that module I didn't think that I would use Ansible to also change configuration through SNMP. Partly because SNMP is well SNMP, but mainly because of the fact that what you can actually change through SNMP is limited. 

However after reading the discussions here and on Twitter about the need to support "legacy" devices using modern tools I figured that I'd take a stab at it anyway.

After looking at different things that you can change using SNMP I settled on creating and removing VLANs and that became the first module, cisco_snmp_vlan.py.

My goal was to create a module which was idempotent that could create, rename and remove VLANs from a switch. I used an 8-port 2960 switch but my guess is that anything running Cisco IOS would work.

If you want to check it out you can find it at Github:
(The readme file has en example of what it could look like when you run a playbook)

Currently the module isn't very user friendly as there's no installer, also I'm using a wrapper module I created for pysnmp called nelsnmp which also doesn't have an installer. But if you want to try it and don't know what to do just let me know and I'll try to help you. My plan is to have nelsnmp available through pip.

At this state the module only supports SNMPv2, but I have the code for SNMPv3 in my other module. I just haven't implemented SNMPv3 in nelsnmp yet. Also in the current version nelsnmp doesn't have any error checking so it won't stop if the snmp community string is incorrect.

This module only changes the running config and my next module will probably be one which saves the config. I've written a Python script for that but haven't converted it to an Ansible module yet. What I was thinking was that when you create a playbook you could register the results from modules such as cisco_snmp_vlan and if a change status is registered Ansible runs the module which saves the config. That way the playbook would remain idempotent.

Anyway I hope someone finds this useful, if you have any comments or suggestions please let me know.

Best regards
Patrick

Ps. And now the hard part, figuring out which open source license I should attach to the project..

 


Jochen Bartl

unread,
Feb 27, 2015, 6:38:52 PM2/27/15
to networ...@googlegroups.com
Patrick Ogenstad wrote:
> ...
> Currently the module isn't very user friendly as there's no installer, also
> I'm using a wrapper module I created for pysnmp called nelsnmp
> <https://github.com/networklore/nelsnmp> which also doesn't have an
> installer. But if you want to try it and don't know what to do just let me
> know and I'll try to help you. My plan is to have nelsnmp available through
> pip.
>
> At this state the module only supports SNMPv2, but I have the code for
> SNMPv3 in my other module. I just haven't implemented SNMPv3 in nelsnmp
> yet. Also in the current version nelsnmp doesn't have any error checking so
> it won't stop if the snmp community string is incorrect.
>

Thanks for sharing Patrick. Maybe you want to have a look at HNMP[1] as
PySNMP wrapper. I'm not the author of it, but added SNMPv3 via pull
requests. It already does get, set, getbulk, has v3 support and is
installable via pip.

Best regards,

Jochen


1.) https://github.com/trehn/hnmp

Patrick Ogenstad

unread,
Mar 1, 2015, 4:36:53 AM3/1/15
to Jochen Bartl, networ...@googlegroups.com
Thanks Jochen. Hnmp doesn't really handle queries the way I want to. However I like the way the values are returned from the queries as it simplifies the handling in the script which uses the module. So I think I'll test to do it that way in nelsnmp instead.


--
You received this message because you are subscribed to the Google Groups "network.toCode()" group.
To unsubscribe from this group and stop receiving emails from it, send an email to networktocod...@googlegroups.com.
To post to this group, send email to networ...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/networktocode/54F10006.1040606%40mailbox.org.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages