Repository: ansible/ansible

Issue:
zabbix_host module error: "'>=' not supported between instances of 'str' and 'int'"
<!---
Verify first that your issue/request is not already reported on GitHub.
THIS FORM WILL BE READ BY A MACHINE, COMPLETE ALL SECTIONS AS DESCRIBED.
Also test if the latest release, and devel branch are affected too.
ALWAYS add information AFTER (OUTSIDE) these html comments.
Otherwise it may end up being automatically closed by our bot. -->

##### SUMMARY
<!--- Explain the problem briefly -->
zabbix_host module raises error when updating configuration values:
```
Failed to update host test1: "'>=' not supported between instances of 'str' and 'int'"
```
Error does not occur when first creating zabbix host, or when there are no changes to apply.

##### ISSUE TYPE
 - Bug Report

##### COMPONENT NAME
<!--- Insert, BELOW THIS COMMENT, the name of the module, plugin, task or feature.
Do not include extra details here, e.g. "vyos_command" not "the network module vyos_command" or the full path-->
zabbix_host

##### ANSIBLE VERSION
<!--- Paste, BELOW THIS COMMENT, verbatim output from "ansible --version" between quotes below -->
```
ansible 2.6.1
  config file = /home/xxx/ansible/ansible_base/ansible.cfg
  configured module search path = ['/home/xxx/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /home/xxx/ansible/aenv/lib/python3.6/site-packages/ansible
  executable location = /home/xxx/ansible/aenv/bin/ansible
  python version = 3.6.5 (default, Apr  1 2018, 05:46:30) [GCC 7.3.0]
```

##### CONFIGURATION
<!--- If using Ansible 2.4 or above, paste, BELOW THIS COMMENT, the results of "ansible-config dump --only-changed"
Otherwise, mention any settings you have changed/added/removed in ansible.cfg
(or using the ANSIBLE_* environment variables).-->
DEFAULT_HOST_LIST(/home/xxx/ansible/ansible_base/ansible.cfg) = ['/home/xxx/ansible/ansible_base/hosts.yaml']
DEFAULT_PRIVATE_KEY_FILE(/home/xxx/ansible/ansible_base/ansible.cfg) = /home/xxx/ansible/ansible_base/ansible_rsa
DEFAULT_ROLES_PATH(/home/xxx/ansible/ansible_base/ansible.cfg) = ['/home/xxx/ansible/ansible_base/roles', '/home/xxx/ansible/ansible_base/roles_galaxy', '/home/xxx/ansible/ansible_base/roles_external']

##### OS / ENVIRONMENT
<!--- Mention, BELOW THIS COMMENT, the OS you are running Ansible from, and the OS you are
managing, or say "N/A" for anything that is not platform-specific.
Also mention the specific version of what you are trying to control,
e.g. if this is a network bug the version of firmware on the network device.-->
OS: Ubuntu 18.04 64-bit
Python version: 3.6.5
zabbix-api version: 0.5.3
Zabbix server: Zabbix 3.4.11 (fresh install)

##### STEPS TO REPRODUCE
<!--- For bugs, show exactly how to reproduce the problem, using a minimal test-case.
For new features, show how the feature would be used. -->
Try to use the zabbix_host module to reconfigure a host in zabbix, changing or adding the host_group for example.

Test playbook:
<!--- Paste example playbooks or commands between quotes below -->
```yaml
- hosts: test1
  tasks:
    - name: Test zabbix
      local_action:
        module: zabbix_host
        server_url: "http://192.168.xxx.yyy/zabbix"
        login_user: "Admin"
        login_password: "zabbix"
        host_name: "{{ inventory_hostname }}"
        host_groups:
          - "Linux servers"
          - "Virtual machines"
        link_templates:
          - "Template OS Linux"
        status: enabled
        state: present
        interfaces:
          - type: 1
            main: 1
            useip: 1
            ip: "{{ ansible_default_ipv4.address }}"
```

Inventory file:
```yaml
all:
  hosts:
    test1:
      ansible_connection: local
    test2:
    test3:
  vars:
    ansible_ssh_user: root

py3_hosts:
  hosts:
    test1:
    test2:
    test3:
  vars:
    ansible_python_interpreter: "/usr/bin/python3"
```
<!--- You can also paste gist.github.com links for larger files -->

##### EXPECTED RESULTS
<!--- What did you expect to happen when running the steps above? -->
Zabbix host configuration would get updated without error

##### ACTUAL RESULTS
<!--- What actually happened? If possible run with extra verbosity (-vvvv) -->
Playbook run stops with the error message:
```Failed to update host test1: '>=' not supported between instances of 'str' and 'int'```

<!--- Paste verbatim command output between quotes below -->
```
(aenv) xxx@test1:~/ansible/ansible_base$ ansible-playbook zabbixtest.yml -vvv
ansible-playbook 2.6.1
  config file = /home/xxx/ansible/ansible_base/ansible.cfg
  configured module search path = ['/home/xxx/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /home/xxx/ansible/aenv/lib/python3.6/site-packages/ansible
  executable location = /home/xxx/ansible/aenv/bin/ansible-playbook
  python version = 3.6.5 (default, Apr  1 2018, 05:46:30) [GCC 7.3.0]
Using /home/xxx/ansible/ansible_base/ansible.cfg as config file
Parsed /home/xxx/ansible/ansible_base/hosts.yaml inventory source with yaml plugin

PLAYBOOK: zabbixtest.yml *******************************************************************************************************************************************************************************************************
1 plays in zabbixtest.yml

PLAY [test1] *******************************************************************************************************************************************************************************************************************

TASK [Gathering Facts] *********************************************************************************************************************************************************************************************************
task path: /home/xxx/ansible/ansible_base/zabbixtest.yml:1
<test1> ESTABLISH LOCAL CONNECTION FOR USER: xxx
<test1> EXEC /bin/sh -c 'echo ~xxx && sleep 0'
<test1> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /home/xxx/.ansible/tmp/ansible-tmp-1531301389.2208893-280135625108506 `" && echo ansible-tmp-1531301389.2208893-280135625108506="` echo /home/xxx/.ansible/tmp/ansible-tmp-1531301389.2208893-280135625108506 `" ) && sleep 0'
Using module file /home/xxx/ansible/aenv/lib/python3.6/site-packages/ansible/modules/system/setup.py
<test1> PUT /home/xxx/.ansible/tmp/ansible-local-127604ksuyjx10/tmpp3apd4uw TO /home/xxx/.ansible/tmp/ansible-tmp-1531301389.2208893-280135625108506/setup.py
<test1> EXEC /bin/sh -c 'chmod u+x /home/xxx/.ansible/tmp/ansible-tmp-1531301389.2208893-280135625108506/ /home/xxx/.ansible/tmp/ansible-tmp-1531301389.2208893-280135625108506/setup.py && sleep 0'
<test1> EXEC /bin/sh -c '/usr/bin/python3 /home/xxx/.ansible/tmp/ansible-tmp-1531301389.2208893-280135625108506/setup.py && sleep 0'
<test1> EXEC /bin/sh -c 'rm -f -r /home/xxx/.ansible/tmp/ansible-tmp-1531301389.2208893-280135625108506/ > /dev/null 2>&1 && sleep 0'
ok: [test1]
META: ran handlers

TASK [Test zabbix] *************************************************************************************************************************************************************************************************************
task path: /home/xxx/ansible/ansible_base/zabbixtest.yml:3
<localhost> ESTABLISH LOCAL CONNECTION FOR USER: xxx
<localhost> EXEC /bin/sh -c 'echo ~xxx && sleep 0'
<localhost> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /home/xxx/.ansible/tmp/ansible-tmp-1531301390.0268269-190133495246230 `" && echo ansible-tmp-1531301390.0268269-190133495246230="` echo /home/xxx/.ansible/tmp/ansible-tmp-1531301390.0268269-190133495246230 `" ) && sleep 0'
Using module file /home/xxx/ansible/aenv/lib/python3.6/site-packages/ansible/modules/monitoring/zabbix/zabbix_host.py
<localhost> PUT /home/xxx/.ansible/tmp/ansible-local-127604ksuyjx10/tmp_eebd3om TO /home/xxx/.ansible/tmp/ansible-tmp-1531301390.0268269-190133495246230/zabbix_host.py
<localhost> EXEC /bin/sh -c 'chmod u+x /home/xxx/.ansible/tmp/ansible-tmp-1531301390.0268269-190133495246230/ /home/xxx/.ansible/tmp/ansible-tmp-1531301390.0268269-190133495246230/zabbix_host.py && sleep 0'
<localhost> EXEC /bin/sh -c '/home/xxx/ansible/aenv/bin/python3 /home/xxx/.ansible/tmp/ansible-tmp-1531301390.0268269-190133495246230/zabbix_host.py && sleep 0'
<localhost> EXEC /bin/sh -c 'rm -f -r /home/xxx/.ansible/tmp/ansible-tmp-1531301390.0268269-190133495246230/ > /dev/null 2>&1 && sleep 0'
The full traceback is:
  File "/tmp/ansible_vu_o28t_/ansible_module_********_host.py", line 324, in update_host
    if proxy_id >= 0:

fatal: [test1 -> localhost]: FAILED! => {
    "changed": false,
    "invocation": {
        "module_args": {
            "description": null,
            "force": true,
            "host_groups": [
                "Linux servers",
                "Virtual machines"
            ],
            "host_name": "test1",
            "http_login_password": null,
            "http_login_user": null,
            "interfaces": [
                {
                    "dns": "",
                    "ip": "192.168.xxx.yyy",
                    "main": 1,
                    "port": "10050",
                    "type": 1,
                    "useip": 1
                }
            ],
            "inventory_mode": null,
            "inventory_zabbix": null,
            "ipmi_authtype": null,
            "ipmi_password": null,
            "ipmi_privilege": null,
            "ipmi_username": null,
            "link_templates": [
                "Template OS Linux"
            ],
            "login_password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
            "login_user": "Admin",
            "proxy": null,
            "server_url": "http://192.168.xxx.zzz/********",
            "state": "present",
            "status": "enabled",
            "timeout": 10,
            "tls_accept": 1,
            "tls_connect": 1,
            "tls_issuer": null,
            "tls_psk": null,
            "tls_psk_identity": null,
            "tls_subject": null,
            "validate_certs": true,
            "visible_name": null
        }
    },
    "msg": "Failed to update host test1: '>=' not supported between instances of 'str' and 'int'"
}
        to retry, use: --limit @/home/xxx/ansible/ansible_base/zabbixtest.retry

PLAY RECAP *********************************************************************************************************************************************************************************************************************
test1                      : ok=1    changed=0    unreachable=0    failed=1
```



Discussion:
Files identified in the description:
* [lib/ansible/modules/monitoring/zabbix/zabbix_host.py](https://github.com/ansible/ansible/blob/devel/lib/ansible/modules/monitoring/zabbix/zabbix_host.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 @D3DeFi @cove @eikef @harrisongu
[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: notify --->

Resolving patch:
diff --git a/lib/ansible/modules/monitoring/zabbix/zabbix_host.py b/lib/ansible/modules/monitoring/zabbix/zabbix_host.py
--- a/lib/ansible/modules/monitoring/zabbix/zabbix_host.py
+++ b/lib/ansible/modules/monitoring/zabbix/zabbix_host.py
@@ -396,7 +396,7 @@ def get_proxyid_by_proxy_name(self, proxy_name):
         if len(proxy_list) < 1:
             self._module.fail_json(msg="Proxy not found: %s" % proxy_name)
         else:
-            return proxy_list[0]['proxyid']
+            return int(proxy_list[0]['proxyid'])
 
     # get group ids by group names
     def get_group_ids_by_group_names(self, group_names):
@@ -763,7 +763,7 @@ def main():
 
         # If proxy is not specified as a module parameter, use the existing setting
         if proxy is None:
-            proxy_id = zabbix_host_obj['proxy_hostid']
+            proxy_id = int(zabbix_host_obj['proxy_hostid'])
 
         if state == "absent":
             # remove host


Test patch: