How to install the Cisco IOS SNMP modules for Ansible

This guide helps you to install the Cisco IOS Ansible SNMP modules. Before you start if you haven’t tried Ansible before it could be a good idea to learn some basics first.

Quick setup

In this example I’m using Ubuntu 14.04 and will install Ansible and the modules to configure Cisco devices using SNMP.

Update machine, install pip and install Ansible using pip along with Nelsnmp which is used by the Ansible modules:

sudo apt-get update
sudo apt-get upgrade
sudo apt-get install python-pip
sudo apt-get install python-dev
sudo pip install ansible
sudo pip install nelsnmp
sudo apt-get install git
git clone https://github.com/networklore/ansible-cisco-snmp.git
cd ansible-cisco-snmp
sudo mkdir -p /etc/ansible
sudo vi /etc/ansible/ansible.cfg

Enter this in the file, where the library variable points to the the location where you downloaded ansible-cisco-snmp to.

[defaults]

library = /home/patrick/ansible-cisco-snmp/library

Now you can modify the example Playbooks or create your own playbooks.

Cisco configuration

To setup SNMPv3 on your devices you can use this config where the access-list allows you to restrict access so that you can only connect from one ip address to actually change the device configuration.

ip access-list standard ACL-ANSIBLE-HOST
 permit host 172.29.50.50

snmp-server view V3ISO iso included

snmp-server group ANSIBLEGRP v3 priv write V3ISO

snmp-server user ansible ANSIBLEGRP v3 auth sha AuthPassword123 priv aes 128 PrivPassword123 access ACL-ANSIBLE-HOST

Things to keep in mind

Since these Cisco devices doesn’t have Python installed and we can’t gather facts the way Ansible normally does we need to disable this in our playbooks with “gather_facts: no”. Also normally Ansible copies the module file to the remove machine and it is run at that location, this isn’t the case with these modules. So the modules must be run locally, this can be done by defining this in a playbook with “connection: local”.

Updates

When updates to the modules are released you might have to upgrade nelsnmp. To download the newer versions of the actual module files you can just issue a “git pull” in your ansible-cisco-snmp directory.

sudo pip install nelsnmp --upgrade

Module documentation

The documentation which describe how to actually use the modules themselves is located in the docs directory over at GitHub.