# Buggy code
def check_all_properties(
    self,
    host_id,
    host_groups,
    status,
    interfaces,
    template_ids,
    exist_interfaces,
    host,
    proxy_id,
    visible_name,
    description,
    host_name,
    inventory_mode,
    inventory_zabbix,
    tls_accept,
    tls_psk_identity,
    tls_psk,
    tls_issuer,
    tls_subject,
    tls_connect,
    ipmi_authtype,
    ipmi_privilege,
    ipmi_username,
    ipmi_password,
):
    # get the existing host's groups
    exist_host_groups = self.get_host_groups_by_host_id(host_id)
    if set(host_groups) != set(exist_host_groups):
        return True

    # get the existing status
    exist_status = self.get_host_status_by_host(host)
    if int(status) != int(exist_status):
        return True

    # check the exist_interfaces whether it equals the interfaces or not
    if self.check_interface_properties(exist_interfaces, interfaces):
        return True

    # get the existing templates
    exist_template_ids = self.get_host_templates_by_host_id(host_id)
    if set(list(template_ids)) != set(exist_template_ids):
        return True

    if int(host["proxy_hostid"]) != int(proxy_id):
        return True

    # Check whether the visible_name has changed; Zabbix defaults to the technical hostname if not set.
    if visible_name:
        if host["name"] != visible_name:
            return True

    # Only compare description if it is given as a module parameter
    if description:
        if host["description"] != description:
            return True

    if inventory_mode:
        if host["inventory"]:
            if int(host["inventory"]["inventory_mode"]) != self.inventory_mode_numeric(
                inventory_mode
            ):
                return True
        elif inventory_mode != "disabled":
            return True

    if inventory_zabbix:
        proposed_inventory = copy.deepcopy(host["inventory"])
        proposed_inventory.update(inventory_zabbix)
        if proposed_inventory != host["inventory"]:
            return True

    if tls_accept is not None and "tls_accept" in host:
        if int(host["tls_accept"]) != tls_accept:
            return True

    if tls_psk_identity is not None and "tls_psk_identity" in host:
        if host["tls_psk_identity"] != tls_psk_identity:
            return True

    if tls_psk is not None and "tls_psk" in host:
        if host["tls_psk"] != tls_psk:
            return True

    if tls_issuer is not None and "tls_issuer" in host:
        if host["tls_issuer"] != tls_issuer:
            return True

    if tls_subject is not None and "tls_subject" in host:
        if host["tls_subject"] != tls_subject:
            return True

    if tls_connect is not None and "tls_connect" in host:
        if int(host["tls_connect"]) != tls_connect:
            return True
    if ipmi_authtype is not None:
        if int(host["ipmi_authtype"]) != ipmi_authtype:
            return True
    if ipmi_privilege is not None:
        if int(host["ipmi_privilege"]) != ipmi_privilege:
            return True
    if ipmi_username is not None:
        if host["ipmi_username"] != ipmi_username:
            return True
    if ipmi_password is not None:
        if host["ipmi_password"] != ipmi_password:
            return True

    return False


# Traceback (KeyError)
TASK [ansible-role-zabbix_web : add zabbix hosts] ******************************
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: KeyError: 'inventory_mode'
failed: [zabbix_web-centos-latest] (item=Example server 1) => {"ansible_loop_var": "item", "changed": false, "item": {"description": "Example server 1 description", "groups": ["Linux servers"], "interface_dns": "server1.example.com", "interface_ip": "192.168.127.127", "link_templates": ["Template OS Linux by Zabbix agent"], "name": "Example server 1", "visible_name": "Example server 1 name"}, "module_stderr": "Traceback (most recent call last):\n  File \"/root/.ansible/tmp/ansible-tmp-1574832740.9065554-150815383322675/AnsiballZ_zabbix_host.py\", line 102, in <module>\n    _ansiballz_main()\n  File \"/root/.ansible/tmp/ansible-tmp-1574832740.9065554-150815383322675/AnsiballZ_zabbix_host.py\", line 94, in _ansiballz_main\n    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\n  File \"/root/.ansible/tmp/ansible-tmp-1574832740.9065554-150815383322675/AnsiballZ_zabbix_host.py\", line 40, in invoke_module\n    runpy.run_module(mod_name='ansible.modules.monitoring.zabbix.zabbix_host', 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_zabbix_host_payload_xl5geyrr/ansible_zabbix_host_payload.zip/ansible/modules/monitoring/zabbix/zabbix_host.py\", line 902, in <module>\n  File \"/tmp/ansible_zabbix_host_payload_xl5geyrr/ansible_zabbix_host_payload.zip/ansible/modules/monitoring/zabbix/zabbix_host.py\", line 862, in main\n  File \"/tmp/ansible_zabbix_host_payload_xl5geyrr/ansible_zabbix_host_payload.zip/ansible/modules/monitoring/zabbix/zabbix_host.py\", line 546, in check_all_properties\nKeyError: 'inventory_mode'\n", "module_stdout": "", "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error", "rc": 1}

# Fixed code
def check_all_properties(
    self,
    host_id,
    host_groups,
    status,
    interfaces,
    template_ids,
    exist_interfaces,
    host,
    proxy_id,
    visible_name,
    description,
    host_name,
    inventory_mode,
    inventory_zabbix,
    tls_accept,
    tls_psk_identity,
    tls_psk,
    tls_issuer,
    tls_subject,
    tls_connect,
    ipmi_authtype,
    ipmi_privilege,
    ipmi_username,
    ipmi_password,
):
    # get the existing host's groups
    exist_host_groups = self.get_host_groups_by_host_id(host_id)
    if set(host_groups) != set(exist_host_groups):
        return True

    # get the existing status
    exist_status = self.get_host_status_by_host(host)
    if int(status) != int(exist_status):
        return True

    # check the exist_interfaces whether it equals the interfaces or not
    if self.check_interface_properties(exist_interfaces, interfaces):
        return True

    # get the existing templates
    exist_template_ids = self.get_host_templates_by_host_id(host_id)
    if set(list(template_ids)) != set(exist_template_ids):
        return True

    if int(host["proxy_hostid"]) != int(proxy_id):
        return True

    # Check whether the visible_name has changed; Zabbix defaults to the technical hostname if not set.
    if visible_name:
        if host["name"] != visible_name:
            return True

    # Only compare description if it is given as a module parameter
    if description:
        if host["description"] != description:
            return True

    if inventory_mode:
        if LooseVersion(self._zbx_api_version) <= LooseVersion("4.4.0"):
            if host["inventory"]:
                if int(
                    host["inventory"]["inventory_mode"]
                ) != self.inventory_mode_numeric(inventory_mode):
                    return True
            elif inventory_mode != "disabled":
                return True
        else:
            if int(host["inventory_mode"]) != self.inventory_mode_numeric(
                inventory_mode
            ):
                return True

    if inventory_zabbix:
        proposed_inventory = copy.deepcopy(host["inventory"])
        proposed_inventory.update(inventory_zabbix)
        if proposed_inventory != host["inventory"]:
            return True

    if tls_accept is not None and "tls_accept" in host:
        if int(host["tls_accept"]) != tls_accept:
            return True

    if tls_psk_identity is not None and "tls_psk_identity" in host:
        if host["tls_psk_identity"] != tls_psk_identity:
            return True

    if tls_psk is not None and "tls_psk" in host:
        if host["tls_psk"] != tls_psk:
            return True

    if tls_issuer is not None and "tls_issuer" in host:
        if host["tls_issuer"] != tls_issuer:
            return True

    if tls_subject is not None and "tls_subject" in host:
        if host["tls_subject"] != tls_subject:
            return True

    if tls_connect is not None and "tls_connect" in host:
        if int(host["tls_connect"]) != tls_connect:
            return True
    if ipmi_authtype is not None:
        if int(host["ipmi_authtype"]) != ipmi_authtype:
            return True
    if ipmi_privilege is not None:
        if int(host["ipmi_privilege"]) != ipmi_privilege:
            return True
    if ipmi_username is not None:
        if host["ipmi_username"] != ipmi_username:
            return True
    if ipmi_password is not None:
        if host["ipmi_password"] != ipmi_password:
            return True

    return False