Repository: ansible-collections/community.vmware

Issue:
Adding support for SNMP syslocation and syscontact configuration
<!--- Verify first that your feature was not already discussed on GitHub -->
<!--- Complete *all* sections as described, this form is processed automatically -->

##### SUMMARY
<!--- Describe the new feature/improvement briefly below -->
Add support for SNMP syscontact and syslocation configuration
##### ISSUE TYPE
- Module improvement

##### COMPONENT NAME
<!--- Write the short name of the module, plugin, task or feature below, use your best guess if unsure -->
community.vmware.vmware_host_snmp

##### ADDITIONAL INFORMATION
<!--- Describe how the feature would be used, why it is needed and what it would solve -->
Currently it is not possible to configure SNMP syscontact and syslocation via mentioned module. The module should provide parameters to do so.

<!--- Paste example playbooks or commands between quotes below -->
```yaml
- name: Enable and configure SNMP
  community.vmware.vmware_host_snmp:
    hostname: '{{ esxi_host }}'
    username: '{{ esxi_user }}'
    password: '{{ esxi_host_pass }}'
    snmp_port: '{{ esxi_snmp_port }}'
    community: [ '{{ esxi_snmp_community }}' ]
    contact: '{{ esxi_snmp_contact }}'
    location: '{{ esxi_snmp_location }}'
    state: enabled
  delegate_to: localhost
```

<!--- HINT: You can also paste gist.github.com links for larger files -->



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 --->
@JayBeeCee: Greetings! Thanks for taking the time to open this issue. In order for the community to handle your issue effectively, we need a bit more information.

Here are the items we could not find in your description:
- ansible version

Please set the description of this issue with this template:
https://raw.githubusercontent.com/ansible/ansible/devel/.github/ISSUE_TEMPLATE/bug_report.md

[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: issue_missing_data --->

Resolving patch:
diff --git a/plugins/modules/vmware_host_snmp.py b/plugins/modules/vmware_host_snmp.py
--- a/plugins/modules/vmware_host_snmp.py
+++ b/plugins/modules/vmware_host_snmp.py
@@ -73,6 +73,16 @@
     type: str
     choices: [ debug, info, warning, error ]
     default: info
+  sys_contact:
+    description:
+        - System contact who manages the system.
+    type: str
+    version_added: '1.17.0'
+  sys_location:
+    description:
+        - System location.
+    type: str
+    version_added: '1.17.0'
 extends_documentation_fragment:
 - community.vmware.vmware.documentation
 
@@ -107,6 +117,16 @@
     state: enabled
   delegate_to: localhost
 
+- name: Enable and configure SNMP system contact and location
+  community.vmware.vmware_host_snmp:
+    hostname: '{{ esxi_hostname }}'
+    username: '{{ esxi_username }}'
+    password: '{{ esxi_password }}'
+    sys_contact: "admin@testemail.com"
+    sys_location: "Austin, USA"
+    state: enabled
+  delegate_to: localhost
+
 - name: Disable SNMP
   community.vmware.vmware_host_snmp:
     hostname: '{{ esxi_hostname }}'
@@ -171,6 +191,8 @@ def ensure(self):
         log_level = self.params.get("log_level")
         send_trap = self.params.get("send_trap")
         trap_filter = self.params.get("trap_filter")
+        sys_contact = self.params.get("sys_contact")
+        sys_location = self.params.get("sys_location")
         event_filter = None
         if trap_filter:
             event_filter = ';'.join(trap_filter)
@@ -207,6 +229,10 @@ def ensure(self):
                     results['log_level_previous'] = option.value
                 if option.key == 'EventFilter' and option.value != hw_source:
                     results['trap_filter_previous'] = option.value.split(';')
+                if option.key == 'syscontact' and option.value != hw_source:
+                    results['syscontact_previous'] = option.value
+                if option.key == 'syslocation' and option.value != hw_source:
+                    results['syslocation_previous'] = option.value
             # Build factory default config
             destination = vim.host.SnmpSystem.SnmpConfigSpec.Destination()
             destination.hostName = ""
@@ -315,6 +341,8 @@ def ensure(self):
             results['log_level'] = log_level
             results['trap_filter'] = trap_filter
             event_filter_found = False
+            sys_contact_found = False
+            sys_location_found = False
             if snmp_config_spec.option:
                 for option in snmp_config_spec.option:
                     if option.key == 'EnvEventSource' and option.value != hw_source:
@@ -334,6 +362,20 @@ def ensure(self):
                             changed_list.append("trap filter")
                             results['trap_filter_previous'] = option.value.split(';')
                             option.value = event_filter
+                    if option.key == 'syscontact':
+                        sys_contact_found = True
+                        if sys_contact is not None and option.value != sys_contact:
+                            changed = True
+                            changed_list.append("sys contact")
+                            results['sys_contact_previous'] = option.value
+                            option.value = sys_contact
+                    if option.key == 'syslocation':
+                        sys_location_found = True
+                        if sys_location is not None and option.value != sys_location:
+                            changed = True
+                            changed_list.append("sys location")
+                            results['sys_location_previous'] = option.value
+                            option.value = sys_location
             if trap_filter and not event_filter_found:
                 changed = True
                 changed_list.append("trap filter")
@@ -351,7 +393,16 @@ def ensure(self):
                 # Doesn't work. Need to reset config instead
                 # snmp_config_spec.option = options
                 reset_hint = True
-
+            if sys_contact and not sys_contact_found:
+                changed = True
+                changed_list.append("sys contact")
+                results['sys_contact_previous'] = ''
+                snmp_config_spec.option.append(self.create_option('syscontact', sys_contact))
+            if sys_location and not sys_location_found:
+                changed = True
+                changed_list.append("sys location")
+                results['sys_location_previous'] = ''
+                snmp_config_spec.option.append(self.create_option('syslocation', sys_location))
         if changed:
             if snmp_state == 'reset':
                 if self.module.check_mode:
@@ -472,6 +523,8 @@ def main():
         hw_source=dict(type='str', default='indications', choices=['indications', 'sensors']),
         log_level=dict(type='str', default='info', choices=['debug', 'info', 'warning', 'error']),
         send_trap=dict(type='bool', default=False),
+        sys_contact=dict(type='str'),
+        sys_location=dict(type='str')
     )
 
     module = AnsibleModule(


Test patch:
diff --git a/tests/integration/targets/vmware_host_snmp/tasks/main.yml b/tests/integration/targets/vmware_host_snmp/tasks/main.yml
--- a/tests/integration/targets/vmware_host_snmp/tasks/main.yml
+++ b/tests/integration/targets/vmware_host_snmp/tasks/main.yml
@@ -41,6 +41,22 @@
           - snmp_enabled is defined
           - snmp_enabled.changed
 
+    - name: Enable and configure SNMP system contact and location
+      vmware_host_snmp:
+        hostname: '{{ esxi1 }}'
+        username: '{{ esxi_user }}'
+        password: '{{ esxi_password }}'
+        sys_contact: "admin@testemail.com"
+        sys_location: "Austin, USA"
+        state: enabled
+        validate_certs: false
+      register: snmp_enabled_sys_options
+    - debug: var=snmp_enabled_sys_options
+    - assert:
+        that:
+          - snmp_enabled_sys_options is defined
+          - snmp_enabled_sys_options.changed
+
     - name: Disable SNMP
       vmware_host_snmp:
         hostname: '{{ esxi1 }}'
@@ -49,8 +65,8 @@
         state: disabled
         validate_certs: false
       register: snmp_disabled
-    - debug: var=snmp_enabled
+    - debug: var=snmp_disabled
     - assert:
         that:
-          - snmp_enabled is defined
-          - snmp_enabled.changed
+          - snmp_disabled is defined
+          - snmp_disabled.changed