# Creating a pull request for snmp\_facts module and suggestions

**URL:** <https://forum.ansible.com/t/creating-a-pull-request-for-snmp-facts-module-and-suggestions/16592>\
**Category:** Ansible Developer\
**Created:** [October 23, 2014, 5:11pm UTC](https://forum.ansible.com/t/creating-a-pull-request-for-snmp-facts-module-and-suggestions/16592 "2014-10-23T17:11:46Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Patrick\_Ogenstad](https://avatars.discourse-cdn.com/v4/letter/p/c37758/32.png) [@Patrick\_Ogenstad](https://forum.ansible.com/u/Patrick_Ogenstad)\
**Post date:** [October 23, 2014, 5:11pm UTC](https://forum.ansible.com/t/creating-a-pull-request-for-snmp-facts-module-and-suggestions/16592/1 "2014-10-23T17:11:46Z")

</div>

I’ve created an Ansible module which can gather Ansible facts from SNMP enabled devices. I’ve written about the module here:  
[http://networklore.com/ansible-snmp-facts/](http://networklore.com/ansible-snmp-facts/)

It was [suggested on Twitter](https://twitter.com/networklore/status/524952321265266688) that I created a pull request to move the module to the extras repo.

My repo is located here:  
[https://github.com/networklore/ansible-snmp-facts](https://github.com/networklore/ansible-snmp-facts)

I’m quite new with Git and I’m not really sure what to do. Can I send a pull request only for the file [snmp\_facts.py](https://github.com/networklore/ansible-snmp-facts/blob/master/library/snmp_facts.py), or how does it work?

Currently the module is quite basic but could be expanded all kinds of other information.

What I’ve been thinking about is how to best structure the data which is returned to Ansible. Currently the return values look like this:

“ansible\_facts”: {  
“ansible\_interfaces”: {  
“1”: {  
“ifindex”: “1”,  
“name”: “Vlan1”  
},  
“10004”: {  
“ifindex”: “10004”,  
“name”: “FastEthernet0/4”  
},  
},

The numbers directly under the ansible\_interfaces is the SNMP ifIndex number. I don’t know if that is ideal, but I think it’s better to use those numbers compared to a name like “FastEthernet0/4”. Does anyone have an input on this?

Another question is if we want to look at CDP information to see how Cisco equipment is connected to each other.

These are the interfaces on one on my switches:

[patrick@srv-script-1 ~]# snmpwalk -v2c -c cisco 172.29.50.3 ifDescr  
IF-MIB::ifDescr.1 = STRING: Vlan1  
IF-MIB::ifDescr.20 = STRING: Vlan20  
IF-MIB::ifDescr.40 = STRING: Vlan40  
IF-MIB::ifDescr.41 = STRING: Vlan41  
IF-MIB::ifDescr.5001 = STRING: Port-channel1  
IF-MIB::ifDescr.10101 = STRING: GigabitEthernet0/1  
IF-MIB::ifDescr.10102 = STRING: GigabitEthernet0/2  
IF-MIB::ifDescr.10103 = STRING: GigabitEthernet0/3  
IF-MIB::ifDescr.10104 = STRING: GigabitEthernet0/4  
IF-MIB::ifDescr.10105 = STRING: GigabitEthernet0/5  
IF-MIB::ifDescr.10106 = STRING: GigabitEthernet0/6  
IF-MIB::ifDescr.10107 = STRING: GigabitEthernet0/7  
IF-MIB::ifDescr.10108 = STRING: GigabitEthernet0/8  
IF-MIB::ifDescr.10501 = STRING: Null0

This is part of the SNMP table for CDP.

CISCO-SMI::ciscoMgmt.23.1.2.1.1.6.10101.5 = STRING: “Switch1”  
CISCO-SMI::ciscoMgmt.23.1.2.1.1.6.10106.1 = STRING: “Router2”  
CISCO-SMI::ciscoMgmt.23.1.2.1.1.6.10106.2 = STRING: “Router1”  
CISCO-SMI::ciscoMgmt.23.1.2.1.1.6.10106.3 = STRING: “Router3”  
CISCO-SMI::ciscoMgmt.23.1.2.1.1.7.10101.5 = STRING: “GigabitEthernet0/1”  
CISCO-SMI::ciscoMgmt.23.1.2.1.1.7.10106.1 = STRING: “GigabitEthernet0/2”  
CISCO-SMI::ciscoMgmt.23.1.2.1.1.7.10106.2 = STRING: “GigabitEthernet0/3”  
CISCO-SMI::ciscoMgmt.23.1.2.1.1.7.10106.3 = STRING: “GigabitEthernet0/2”

We can see that we have one device called Switch is connected to the 10101 interface (GigabitEthernet0/1) and three devices called router1, router2 and router3 which are connected through the interface 10106 (GigabitEthernet0/6). So on one interface there is a one to one relationship, but on the other local interface there is a one to three relation.

It wouldn’t be a problem to store this in a database with two tables, but I’m unsure of the best structure with Ansible facts. Perhaps the best way is to solve it like the IPv6 addresses in Ansible now, I’m unsure about the terminology, but “unnamed keys” or something:

“ansible\_eth1”: {  
“active”: true,  
“device”: “eth1”,  
“ipv4”: {  
“address”: “10.10.20.1”,  
“netmask”: “255.255.255.0”,  
“network”: “10.10.20.0”  
},  
“ipv6”: [  
{  
“address”: “2201::1”,  
“prefix”: “64”,  
“scope”: “global”  
},  
{  
“address”: “2001::1”,  
“prefix”: “64”,  
“scope”: “global”  
},  
{  
“address”: “fe80::20c:29ff:fe25:c94c”,  
“prefix”: “64”,  
“scope”: “link”  
}  
],

If someone have any suggestions about this I’m all ears.

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [October 25, 2014, 1:56am UTC](https://forum.ansible.com/t/creating-a-pull-request-for-snmp-facts-module-and-suggestions/16592/2 "2014-10-25T01:56:05Z")

</div>

Hi Patrick,

I think I replied to a recent SNMP post earlier, so this may be a stray email in drafts.

Let me know if this is not a dup and there are specific new things you’d like input on.

–Michael
