Repository: ansible/ansible

Issue:
zabbix_template module error: TypeError: '<' not supported between instances of 'int' and 'str'
##### ISSUE TYPE
 - Bug Report

##### COMPONENT NAME
zabbix_template

##### ANSIBLE VERSION
```
ansible 2.5.1
  config file = None
  configured module search path = ['/Users/amatellanes/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /Users/amatellanes/.virtualenvs/pipeline-downloads_ansible3/lib/python3.6/site-packages/ansible
  executable location = /Users/amatellanes/.virtualenvs/pipeline-downloads_ansible3/bin/ansible
  python version = 3.6.5 (default, Mar 30 2018, 06:41:53) [GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.39.2)]
```

##### CONFIGURATION

##### OS / ENVIRONMENT
System Version: macOS 10.13.4 (17E199)
Kernel Version: Darwin 17.5.0

##### SUMMARY
When I am using `zabbix_template` module with Python 3, Ansible returns this error:
```
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
````

##### 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. -->

<!--- Paste example playbooks or commands between quotes below -->
Using Ansible with Python 3, run the following task:

```yaml
- name: import zabbix template configuration
  local_action:
    module: zabbix_template
    server_url: "{{ zabbix_server_url }}"
    login_user: "{{ zabbix_login_user }}"
    login_password: "{{ zabbix_login_password }}"
    template_name: "{{ zabbix_fluentd_template_name }}"
    template_json: "{{ lookup('file', 'zabbix_fluentd.json') }}"
    template_groups: "{{ zabbix_fluentd_host_groups }}"
  ignore_errors: "{{ ansible_check_mode }}"
```

<!--- You can also paste gist.github.com links for larger files -->

##### EXPECTED RESULTS
Zabbix template should be imported successfully and no errors should be raised.

##### ACTUAL RESULTS
Ansible returns this error:

```
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'
```



Discussion:

Resolving patch:
diff --git a/lib/ansible/modules/monitoring/zabbix/zabbix_template.py b/lib/ansible/modules/monitoring/zabbix/zabbix_template.py
--- a/lib/ansible/modules/monitoring/zabbix/zabbix_template.py
+++ b/lib/ansible/modules/monitoring/zabbix/zabbix_template.py
@@ -417,7 +417,8 @@ def import_template(self, template_json, template_name=None):
             # 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'):
+            if LooseVersion(api_version).version[:2] <= LooseVersion(
+                    '3.2').version:
                 update_rules['applications']['updateExisting'] = True
 
             self._zapi.configuration.import_({


Test patch: