# Buggy code
def import_template(self, template_json, template_name=None):
    parsed_template_json = self.load_json_template(template_json)
    if (
        template_name
        != parsed_template_json["zabbix_export"]["templates"][0]["template"]
    ):
        self._module.fail_json(msg="JSON template name does not match presented name")

    # rules schema latest version
    update_rules = {
        "applications": {"createMissing": True, "deleteMissing": True},
        "discoveryRules": {
            "createMissing": True,
            "updateExisting": True,
            "deleteMissing": True,
        },
        "graphs": {
            "createMissing": True,
            "updateExisting": True,
            "deleteMissing": True,
        },
        "httptests": {
            "createMissing": True,
            "updateExisting": True,
            "deleteMissing": True,
        },
        "items": {"createMissing": True, "updateExisting": True, "deleteMissing": True},
        "templates": {"createMissing": True, "updateExisting": True},
        "templateScreens": {
            "createMissing": True,
            "updateExisting": True,
            "deleteMissing": True,
        },
        "triggers": {
            "createMissing": True,
            "updateExisting": True,
            "deleteMissing": True,
        },
        "valueMaps": {"createMissing": True, "updateExisting": True},
    }

    try:
        # old api version support here
        api_version = self._zapi.api_version()
        # updateExisting for application removed from zabbix api after 3.2
        if LooseVersion(api_version) <= LooseVersion("3.2.x"):
            update_rules["applications"]["updateExisting"] = True

        self._zapi.configuration.import_(
            {"format": "json", "source": template_json, "rules": update_rules}
        )
    except ZabbixAPIException as e:
        self._module.fail_json(
            msg="Unable to import JSON template",
            details=to_native(e),
            exception=traceback.format_exc(),
        )


# Traceback (TypeError)
TASK [zabbix-config : import zabbix template configuration] *************************************************************************************************************************************
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: TypeError: '<' not supported between instances of 'int' and 'str'
fatal: [centos-7 -> localhost]: FAILED! => {"changed": false, "module_stderr": "Traceback (most recent call last):\n  File \"/var/folders/td/jwgywnqd1c3dtsbncw2_shww0000gn/T/ansible_hkv1xucm/ansible_module_zabbix_template.py\", line 555, in <module>\n    main()\n  File \"/var/folders/td/jwgywnqd1c3dtsbncw2_shww0000gn/T/ansible_hkv1xucm/ansible_module_zabbix_template.py\", line 548, in main\n    existing_template_json)\n  File \"/var/folders/td/jwgywnqd1c3dtsbncw2_shww0000gn/T/ansible_hkv1xucm/ansible_module_zabbix_template.py\", line 309, in update_template\n    existing_template_json['zabbix_export']['templates'][0]['template'])\n  File \"/var/folders/td/jwgywnqd1c3dtsbncw2_shww0000gn/T/ansible_hkv1xucm/ansible_module_zabbix_template.py\", line 420, in import_template\n    if LooseVersion(api_version) <= LooseVersion('3.2.x'):\n  File \"/usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6/lib/python3.6/distutils/version.py\", line 58, in __le__\n    c = self._cmp(other)\n  File \"/usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6/lib/python3.6/distutils/version.py\", line 337, in _cmp\n    if self.ve

# Fixed code
def import_template(self, template_json, template_name=None):
    parsed_template_json = self.load_json_template(template_json)
    if (
        template_name
        != parsed_template_json["zabbix_export"]["templates"][0]["template"]
    ):
        self._module.fail_json(msg="JSON template name does not match presented name")

    # rules schema latest version
    update_rules = {
        "applications": {"createMissing": True, "deleteMissing": True},
        "discoveryRules": {
            "createMissing": True,
            "updateExisting": True,
            "deleteMissing": True,
        },
        "graphs": {
            "createMissing": True,
            "updateExisting": True,
            "deleteMissing": True,
        },
        "httptests": {
            "createMissing": True,
            "updateExisting": True,
            "deleteMissing": True,
        },
        "items": {"createMissing": True, "updateExisting": True, "deleteMissing": True},
        "templates": {"createMissing": True, "updateExisting": True},
        "templateScreens": {
            "createMissing": True,
            "updateExisting": True,
            "deleteMissing": True,
        },
        "triggers": {
            "createMissing": True,
            "updateExisting": True,
            "deleteMissing": True,
        },
        "valueMaps": {"createMissing": True, "updateExisting": True},
    }

    try:
        # old api version support here
        api_version = self._zapi.api_version()
        # updateExisting for application removed from zabbix api after 3.2
        if LooseVersion(api_version).version[:2] <= LooseVersion("3.2").version:
            update_rules["applications"]["updateExisting"] = True

        self._zapi.configuration.import_(
            {"format": "json", "source": template_json, "rules": update_rules}
        )
    except ZabbixAPIException as e:
        self._module.fail_json(
            msg="Unable to import JSON template",
            details=to_native(e),
            exception=traceback.format_exc(),
        )