Repository: ansible-collections/community.general

Issue:
community.general.snmp_facts    "msg": "No SNMP response received before timeout"
<!--- Verify first that your issue is not already reported on GitHub -->
<!--- Also test if the latest release and devel branch are affected too -->
<!--- Complete *all* sections as described, this form is processed automatically -->

##### SUMMARY
community.general.snmp_facts timeouts with No SNMP response received before timeout. Would be nice to increase the timeout or make the timeout configurable 
##### ISSUE TYPE
- Bug Report

##### COMPONENT NAME
snmp_facts

##### ANSIBLE VERSION
ansible 2.9.13
  config file = /home/feisa/ansible-network/ansible.cfg
  configured module search path = ['/home/feisa/ansible-network/library']
  ansible python module location = /usr/lib/python3.6/site-packages/ansible
  executable location = /usr/bin/ansible
  python version = 3.6.8 (default, Dec  5 2019, 15:45:45) [GCC 8.3.1 20191121 (Red Hat 8.3.1-5)]

##### CONFIGURATION

##### OS / ENVIRONMENT
cisco 3850

##### STEPS TO REPRODUCE
```
- name: Gather SNMP Facts 
  community.general.snmp_facts:
    host: "{{ inventory_hostname }}"
    version: v3
    username: snmp
    privacy: aes
    level: authPriv
    integrity: sha
    authkey: "{{ snmpv3 }}"
    privkey: "{{ snmpv3 }}"
  delegate_to: localhost
  no_log: false
  register: snmp_facts
  tags:
    - ios-gather-facts
```
##### EXPECTED RESULTS


##### ACTUAL RESULTS
```
        }
    },
    "msg": "No SNMP response received before timeout"
}
```




Discussion:
Files identified in the description:
None

If these files are inaccurate, please update the `component name` section of the description or use the `!component` bot command.

[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: components_banner --->
Files identified in the description:
* [`plugins/modules/net_tools/snmp_facts.py`](https://github.com/ansible-collections/community.general/blob/master/plugins/modules/net_tools/snmp_facts.py)

If these files are inaccurate, please update the `component name` section of the description or use the `!component` bot command.

[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: components_banner --->
cc @bigmstone @nerzhul @ogenstad @ujwalkomarla
[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: notify --->
@Akasurde any update?
@feisa it looks like nobody volunteered to implement a timeout parameter for this module yet.

Resolving patch:
diff --git a/plugins/modules/net_tools/snmp_facts.py b/plugins/modules/net_tools/snmp_facts.py
--- a/plugins/modules/net_tools/snmp_facts.py
+++ b/plugins/modules/net_tools/snmp_facts.py
@@ -67,6 +67,16 @@
             - Encryption key.
             - Required if I(level) is C(authPriv).
         type: str
+    timeout:
+        description:
+            - Response timeout in seconds.
+        type: int
+        version_added: 2.3.0
+    retries:
+        description:
+            - Maximum number of request retries, 0 retries means just a single request.
+        type: int
+        version_added: 2.3.0
 '''
 
 EXAMPLES = r'''
@@ -271,6 +281,8 @@ def main():
             privacy=dict(type='str', choices=['aes', 'des']),
             authkey=dict(type='str', no_log=True),
             privkey=dict(type='str', no_log=True),
+            timeout=dict(type='int'),
+            retries=dict(type='int'),
         ),
         required_together=(
             ['username', 'level', 'integrity', 'authkey'],
@@ -285,6 +297,7 @@ def main():
         module.fail_json(msg=missing_required_lib('pysnmp'), exception=PYSNMP_IMP_ERR)
 
     cmdGen = cmdgen.CommandGenerator()
+    transport_opts = dict((k, m_args[k]) for k in ('timeout', 'retries') if m_args[k] is not None)
 
     # Verify that we receive a community when using snmp v2
     if m_args['version'] in ("v2", "v2c"):
@@ -333,7 +346,7 @@ def Tree():
 
     errorIndication, errorStatus, errorIndex, varBinds = cmdGen.getCmd(
         snmp_auth,
-        cmdgen.UdpTransportTarget((m_args['host'], 161)),
+        cmdgen.UdpTransportTarget((m_args['host'], 161), **transport_opts),
         cmdgen.MibVariable(p.sysDescr,),
         cmdgen.MibVariable(p.sysObjectId,),
         cmdgen.MibVariable(p.sysUpTime,),
@@ -364,7 +377,7 @@ def Tree():
 
     errorIndication, errorStatus, errorIndex, varTable = cmdGen.nextCmd(
         snmp_auth,
-        cmdgen.UdpTransportTarget((m_args['host'], 161)),
+        cmdgen.UdpTransportTarget((m_args['host'], 161), **transport_opts),
         cmdgen.MibVariable(p.ifIndex,),
         cmdgen.MibVariable(p.ifDescr,),
         cmdgen.MibVariable(p.ifMtu,),


Test patch: