Hi Patrick,
SNMP can definitely be a beast.
I’d be interested if seeing if you could share an example of some of the output from the snmp module.
My other piece of advice would probably be to define constants for each of the MIB values, and see if there is an snmp library defines any of these (it might not).
I’d also move the import to the top of the file, and enclose it in a try/except ImportError block, so it can produce a nice error when something is not defined.
calls like “print json.dumps” can be replaced with the “fail_json” and “exit_json” calls you can see throughout AnsibleModule code.
You can also use the “required_together” feature of argument_spec (grep through the code) to simplify some of the argument checking.
Variables that are not constants, like SNMP_AUTH should be downcased (“snmp_auth”)
Additionally, some duplication like:
snmp_result[‘ansible_facts’]
throughout the system
Could be done just by having the final module return like so:
exit_json(ansible_facts=results)
As you can find done by ‘setup’, the most basic ansible facts module.
Hope that helps for starters
My other thought is different types of devices might not surface the same types of things, so it may be possible your module is written for certain network hardware – which might make the module not generally applicable? (i.e. is it always true that an SNMP thing has an IP address?)
Possibly something to think about.