Repository: ansible-collections/community.vmware

Issue:
vmware_dvs_portgroup_find TypeError: '<' not supported between instances of 'str' and 'int'
##### SUMMARY
<!--- Explain the problem briefly below -->

##### ISSUE TYPE
- Bug Report

##### COMPONENT NAME
vmware_dvs_portgroup_find

##### ANSIBLE VERSION
<!--- Paste verbatim output from "ansible --version" between quotes -->
```paste below
ansible 2.9.5
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/home/awx/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3.6/site-packages/ansible
  executable location = /usr/bin/ansible
  python version = 3.6.8 (default, Nov 21 2019, 19:31:34) [GCC 8.3.1 20190507 (Red Hat 8.3.1-4)]
```

##### CONFIGURATION
<!--- Paste verbatim output from "ansible-config dump --only-changed" between quotes -->
```paste below

```

##### OS / ENVIRONMENT
<!--- Provide all relevant information below, e.g. target OS versions, network device firmware, etc. -->
docker -> ansible/awx_task:11

##### STEPS TO REPRODUCE
<!--- Describe exactly how to reproduce the problem, using a minimal test-case -->

<!--- Paste example playbooks or commands between quotes below -->
```yaml
- name: Confirm if vlan 15 is present
  vmware_dvs_portgroup_find:
    hostname: "{{ vcenter_hostname }}"
    username: "{{ vcenter_username }}"
    password: "{{ vcenter_password }}"
    vlanid: '15'
    validate_certs: no
  delegate_to: localhost
```
<!--- HINT: You can paste gist.github.com links for larger files -->

##### EXPECTED RESULTS
<!--- Describe what you expected to happen when running the steps above -->
```paste below
"msg": {
        "changed": false,
        "dvs_portgroups": [
            {
                "name": "Test_1",
                "trunk": false,
                "pvlan": false,
                "vlan_id": "15",
                "dvswitch": "myDVSwitch"
            },
            {
                "name": "My-Uplinks",
                "trunk": true,
                "pvlan": false,
                "vlan_id": "0-4094",
                "dvswitch": "myDVSwitch"
            },
...


```
##### ACTUAL RESULTS
<!--- Describe what actually happened. If possible run with extra verbosity (-vvvv) -->

<!--- Paste verbatim command output between quotes -->
```paste below
"msg": {
    "module_stdout": "",
    "module_stderr": "Traceback (most recent call last):\n  File \"/root/.ansible/tmp/ansible-tmp-1587460742.276308-276582575233091/AnsiballZ_vmware_dvs_portgroup_find.py\", line 102, in <module>\n    _ansiballz_main()\n  File \"/root/.ansible/tmp/ansible-tmp-1587460742.276308-276582575233091/AnsiballZ_vmware_dvs_portgroup_find.py\", line 94, in _ansiballz_main\n    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\n  File \"/root/.ansible/tmp/ansible-tmp-1587460742.276308-276582575233091/AnsiballZ_vmware_dvs_portgroup_find.py\", line 40, in invoke_module\n    runpy.run_module(mod_name='ansible.modules.cloud.vmware.vmware_dvs_portgroup_find', init_globals=None, run_name='__main__', alter_sys=True)\n  File \"/usr/lib64/python3.6/runpy.py\", line 205, in run_module\n    return _run_module_code(code, init_globals, run_name, mod_spec)\n  File \"/usr/lib64/python3.6/runpy.py\", line 96, in _run_module_code\n    mod_name, mod_spec, pkg_name, script_name)\n  File \"/usr/lib64/python3.6/runpy.py\", line 85, in _run_code\n    exec(code, run_globals)\n  File \"/tmp/ansible_vmware_dvs_portgroup_find_payload_7hp8sciy/ansible_vmware_dvs_portgroup_find_payload.zip/ansible/modules/cloud/vmware/vmware_dvs_portgroup_find.py\", line 213, in <module>\n  File \"/tmp/ansible_vmware_dvs_portgroup_find_payload_7hp8sciy/ansible_vmware_dvs_portgroup_find_payload.zip/ansible/modules/cloud/vmware/vmware_dvs_portgroup_find.py\", line 209, in main\n  File \"/tmp/ansible_vmware_dvs_portgroup_find_payload_7hp8sciy/ansible_vmware_dvs_portgroup_find_payload.zip/ansible/modules/cloud/vmware/vmware_dvs_portgroup_find.py\", line 173, in get_dvs_portgroup\n  File \"/tmp/ansible_vmware_dvs_portgroup_find_payload_7hp8sciy/ansible_vmware_dvs_portgroup_find_payload.zip/ansible/modules/cloud/vmware/vmware_dvs_portgroup_find.py\", line 141, in vlan_match\nTypeError: '<' not supported between instances of 'str' and 'int'\n",
    "exception": "Traceback (most recent call last):\n  File \"/root/.ansible/tmp/ansible-tmp-1587460742.276308-276582575233091/AnsiballZ_vmware_dvs_portgroup_find.py\", line 102, in <module>\n    _ansiballz_main()\n  File \"/root/.ansible/tmp/ansible-tmp-1587460742.276308-276582575233091/AnsiballZ_vmware_dvs_portgroup_find.py\", line 94, in _ansiballz_main\n    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\n  File \"/root/.ansible/tmp/ansible-tmp-1587460742.276308-276582575233091/AnsiballZ_vmware_dvs_portgroup_find.py\", line 40, in invoke_module\n    runpy.run_module(mod_name='ansible.modules.cloud.vmware.vmware_dvs_portgroup_find', init_globals=None, run_name='__main__', alter_sys=True)\n  File \"/usr/lib64/python3.6/runpy.py\", line 205, in run_module\n    return _run_module_code(code, init_globals, run_name, mod_spec)\n  File \"/usr/lib64/python3.6/runpy.py\", line 96, in _run_module_code\n    mod_name, mod_spec, pkg_name, script_name)\n  File \"/usr/lib64/python3.6/runpy.py\", line 85, in _run_code\n    exec(code, run_globals)\n  File \"/tmp/ansible_vmware_dvs_portgroup_find_payload_7hp8sciy/ansible_vmware_dvs_portgroup_find_payload.zip/ansible/modules/cloud/vmware/vmware_dvs_portgroup_find.py\", line 213, in <module>\n  File \"/tmp/ansible_vmware_dvs_portgroup_find_payload_7hp8sciy/ansible_vmware_dvs_portgroup_find_payload.zip/ansible/modules/cloud/vmware/vmware_dvs_portgroup_find.py\", line 209, in main\n  File \"/tmp/ansible_vmware_dvs_portgroup_find_payload_7hp8sciy/ansible_vmware_dvs_portgroup_find_payload.zip/ansible/modules/cloud/vmware/vmware_dvs_portgroup_find.py\", line 173, in get_dvs_portgroup\n  File \"/tmp/ansible_vmware_dvs_portgroup_find_payload_7hp8sciy/ansible_vmware_dvs_portgroup_find_payload.zip/ansible/modules/cloud/vmware/vmware_dvs_portgroup_find.py\", line 141, in vlan_match\nTypeError: '<' not supported between instances of 'str' and 'int'\n",
    "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error",
    "rc": 1,
    "_ansible_no_log": false,
    "changed": false
}
```
##### POSSIBLE SOLLUTION?
cast as integer

```paste below
filename: vmware_dvs_portgroup_find.py
line 133ff:

    def vlan_match(self, pgup, userup, vlanlst):
        res = False
        if pgup and userup:
            return True

        for ln in vlanlst:
            if '-' in ln:
                arr = ln.split('-')
                if int(arr[0]) < self.vlan and self.vlan < int(arr[1]):
                    res = True
            elif ln == str(self.vlan):
                res = True

        return res
```



Discussion:

Resolving patch:
diff --git a/plugins/modules/vmware_dvs_portgroup_find.py b/plugins/modules/vmware_dvs_portgroup_find.py
--- a/plugins/modules/vmware_dvs_portgroup_find.py
+++ b/plugins/modules/vmware_dvs_portgroup_find.py
@@ -141,7 +141,7 @@ def vlan_match(self, pgup, userup, vlanlst):
         for ln in vlanlst:
             if '-' in ln:
                 arr = ln.split('-')
-                if arr[0] < self.vlan and self.vlan < arr[1]:
+                if int(arr[0]) < self.vlan and self.vlan < int(arr[1]):
                     res = True
             elif ln == str(self.vlan):
                 res = True


Test patch: