0

I'm trying to retrieve some information from a cisco switch via snmp_facts module (yes pysnmp is installed on my ansible host). I keep getting this error:

TASK [snmp_facts] ******************************************************************************** fatal: [10.1.1.1]: FAILED! => changed=false msg: Missing required pysnmp module (check docs)

This is the command I am running:

ansible 192.168.1.11 -m snmp_facts -a 'community=blah host={{ inventory_hostname }} version=v2c' -k

From playbooks I wrote earlier, I used delegate_to: localhost but haven't been successful, it doesn't look like a valid option

MrRobot
  • 93
  • 1
  • 2
  • 7
  • What if you just run the task on `localhost`? `ansible localhost -m snmp_facts ...`? Specify the actual hostname rather than using `inventory_hostname`. – larsks Dec 05 '18 at 18:35
  • Same result: #ansible localhost -m snmp_facts -a 'community=blah host=192.168.1.11 version=v2c TASK [snmp_facts] fatal: [localhost]: FAILED! => changed=false msg: Missing required pysnmp module (check docs) # sudo yum install pysnmp package pysnmp-4.2.5-2.el6.noarch already installed and latest version Nothing to do – MrRobot Dec 05 '18 at 18:45

1 Answers1

0

pysnmp is installed on my ansible host

If that's true, you'll need to have ansible run that module using the python that contains pysnmp, not the one that is running ansible (as they can, and very often are, different)

It's close to what @larsks said:

ansible -c local -i localhost, \
    -e ansible_python_interpreter=/the/path/to/the/pysnmp/python ...
mdaniel
  • 31,240
  • 5
  • 55
  • 58
  • What is the actual file within pysnmp directory called? Here's what I am seeing:sh-4.1$ ls cache.py cache.pyo debug.py debug.pyo error.py error.pyo __init__.pyc nextid.py nextid.pyo smi cache.pyc carrier debug.pyc entity error.pyc __init__.py __init__.pyo nextid.pyc proto -sh-4.1$ pwd /usr/lib/python2.6/site-packages/pysnmp – MrRobot Dec 06 '18 at 15:53
  • The correct test is to see that it actually loads, such as `python2.6 -c "import pysnmp"` and then, assuming that works, set `ansible_python_interpreter=/usr/bin/python2.6` or whatever. – mdaniel Dec 06 '18 at 16:18
  • First test worked, specifying the interpreter did not and threw the same error previously seen. – MrRobot Dec 06 '18 at 19:29
  • It's possible the `pysnmp` is too old or something; can you execute [this import](https://github.com/ansible/ansible/blob/v2.7.2/lib/ansible/modules/net_tools/snmp_facts.py#L170) and see what happens? – mdaniel Dec 07 '18 at 04:36
  • python2.6 -c "from pysnmp.entity.rfc3413.oneliner import cmdgen" returns "Import Error: No module named compat.octets" python2.6 -c "import cmdgen" returns error: "No module named cmdgen" – MrRobot Dec 07 '18 at 15:38
  • https://stackoverflow.com/questions/16303512/pysnmp-importerror-no-module-named-pyasn1-compat-octets – mdaniel Dec 07 '18 at 16:21