Skip to content

Commit

Permalink
zabbix_template: Fix encode error occurs when using Python2 (#297)
Browse files Browse the repository at this point in the history
* Fix encode error occurs when using Python2 #233

* update modules

* add changelog file

* fix yamllint error

* Update changelogs/fragments/297-zabbix_template_modules.yml

Co-authored-by: Dusan Matejka <matejkadusan32@gmail.com>

Co-authored-by: Dusan Matejka <matejkadusan32@gmail.com>
  • Loading branch information
sky-joker and D3DeFi authored Dec 27, 2020
1 parent ecf1bfc commit 21284a5
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
3 changes: 3 additions & 0 deletions changelogs/fragments/297-zabbix_template_modules.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
bugfixes:
- zabbix_template - fixed encode error when using Python2 (https://github.com/ansible-collections/community.zabbix/pull/297).
- zabbix_template_info - fixed encode error when using Python2 (https://github.com/ansible-collections/community.zabbix/pull/297).
6 changes: 5 additions & 1 deletion plugins/modules/zabbix_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,7 @@
from distutils.version import LooseVersion
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils._text import to_native
from ansible.module_utils.six import PY2

from ansible_collections.community.zabbix.plugins.module_utils.base import ZabbixBase
import ansible_collections.community.zabbix.plugins.module_utils.helpers as zabbix_utils
Expand Down Expand Up @@ -469,7 +470,10 @@ def dump_template(self, template_ids, template_type='json', omit_date=False):
date = xmlroot.find(".date")
if date is not None:
xmlroot.remove(date)
return str(ET.tostring(xmlroot, encoding='utf-8').decode('utf-8'))
if PY2:
return str(ET.tostring(xmlroot, encoding='utf-8'))
else:
return str(ET.tostring(xmlroot, encoding='utf-8').decode('utf-8'))
else:
return self.load_json_template(dump, omit_date=omit_date)

Expand Down
6 changes: 5 additions & 1 deletion plugins/modules/zabbix_template_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@

from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils._text import to_native
from ansible.module_utils.six import PY2

from ansible_collections.community.zabbix.plugins.module_utils.base import ZabbixBase
import ansible_collections.community.zabbix.plugins.module_utils.helpers as zabbix_utils
Expand Down Expand Up @@ -188,7 +189,10 @@ def dump_template(self, template_id, template_type='json', omit_date=False):
date = xmlroot.find(".date")
if date is not None:
xmlroot.remove(date)
return str(ET.tostring(xmlroot, encoding='utf-8').decode('utf-8'))
if PY2:
return str(ET.tostring(xmlroot, encoding='utf-8'))
else:
return str(ET.tostring(xmlroot, encoding='utf-8').decode('utf-8'))
else:
return self.load_json_template(dump, omit_date)
except Exception as e:
Expand Down

0 comments on commit 21284a5

Please sign in to comment.