ansible-collections / community.zabbix

Zabbix Ansible modules
http://galaxy.ansible.com/community/zabbix
Other
322 stars 284 forks source link

Zabbix 5.2, Error: a bytes-like object is required, not 'str' #397

Closed vanohaker closed 3 years ago

vanohaker commented 3 years ago
SUMMARY

Can not import a template with the zabbix_template module.

ISSUE TYPE
COMPONENT NAME

zabbix_template module

ANSIBLE VERSION
ansible 2.9.20
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/home/iglazkov/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/lib/python3.8/dist-packages/ansible
  executable location = /usr/local/bin/ansible
  python version = 3.8.5 (default, May 27 2021, 13:30:53) [GCC 9.3.0]
CONFIGURATION
DEFAULT_VAULT_PASSWORD_FILE(env: ANSIBLE_VAULT_PASSWORD_FILE) = /home/iglazkov/.vault_pass.txt
OS / ENVIRONMENT / Zabbix Version

playbook executed in: Distributor ID: Neon Description: KDE neon User Edition 5.22 Release: 20.04 Codename: focal docker container executed in: centos 7.9.2009 Zabbix 5.2 server in docker (ubuntu) Zabbix 5.2 web in docker (ubuntu) postgres (PostgreSQL) 13.3 (Debian 13.3-1.pgdg100+1) community.zabbix version 1.3.0

STEPS TO REPRODUCE
https://github.com/Huawei/Server_Management_Plugin_Zabbix.git

paste the path to the xml file into template_xml

- name: import ibmc template for huawei server
  local_action:
    module: zabbix_template
    server_url: "{{ zabbix_url }}" # api url
    login_user: "{{ zabbix_admin_user }}" # zabbix user 
    login_password: "{{ zabbix_admin_password }}" # zabbix password
    template_xml: "{{ lookup('file', '/opt/IBMC_Huawei_server_template/Huawei Chassis SWI Template V1.2.xml') }}"
    state: present
EXPECTED RESULTS

successful import

ACTUAL RESULTS
TASK [apps_in_containers : import ibmc template for huawei server] *************************************************************************************************
task path: /home/iglazkov/git/apps/roles/apps_in_containers/tasks/zabbix_templates.yml:22
Trying secret FileVaultSecret(filename='/home/iglazkov/.vault_pass.txt') for vault_id=default
File lookup using /opt/IBMC_Huawei_server_template/Huawei Chassis SWI Template V1.2.xml as file
<localhost> ESTABLISH LOCAL CONNECTION FOR USER: iglazkov
<localhost> EXEC /bin/sh -c 'echo ~iglazkov && sleep 0'
<localhost> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /home/iglazkov/.ansible/tmp `"&& mkdir "` echo /home/iglazkov/.ansible/tmp/ansible-tmp-1623850968.0569956-41330-84151850272497 `" && echo ansible-tmp-1623850968.0569956-41330-84151850272497="` echo /home/iglazkov/.ansible/tmp/ansible-tmp-1623850968.0569956-41330-84151850272497 `" ) && sleep 0'
Using module file /usr/local/lib/python3.8/dist-packages/ansible/modules/monitoring/zabbix/zabbix_template.py
<localhost> PUT /home/iglazkov/.ansible/tmp/ansible-local-40960hi9uf1tu/tmpdakzl1n3 TO /home/iglazkov/.ansible/tmp/ansible-tmp-1623850968.0569956-41330-84151850272497/AnsiballZ_zabbix_template.py
<localhost> EXEC /bin/sh -c 'chmod u+x /home/iglazkov/.ansible/tmp/ansible-tmp-1623850968.0569956-41330-84151850272497/ /home/iglazkov/.ansible/tmp/ansible-tmp-1623850968.0569956-41330-84151850272497/AnsiballZ_zabbix_template.py && sleep 0'
<localhost> EXEC /bin/sh -c 'sudo -H -S  -p "[sudo via ansible, key=orueshkkpqeiukfjiskggqvtckwwkgsz] password:" -u root /bin/sh -c '"'"'echo BECOME-SUCCESS-orueshkkpqeiukfjiskggqvtckwwkgsz ; /usr/bin/python3 /home/iglazkov/.ansible/tmp/ansible-tmp-1623850968.0569956-41330-84151850272497/AnsiballZ_zabbix_template.py'"'"' && sleep 0'
<localhost> EXEC /bin/sh -c 'rm -f -r /home/iglazkov/.ansible/tmp/ansible-tmp-1623850968.0569956-41330-84151850272497/ > /dev/null 2>&1 && sleep 0'
The full traceback is:
Traceback (most recent call last):
  File "/home/iglazkov/.ansible/tmp/ansible-tmp-1623850968.0569956-41330-84151850272497/AnsiballZ_zabbix_template.py", line 102, in <module>
    _ansiballz_main()
  File "/home/iglazkov/.ansible/tmp/ansible-tmp-1623850968.0569956-41330-84151850272497/AnsiballZ_zabbix_template.py", line 94, in _ansiballz_main
    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)
  File "/home/iglazkov/.ansible/tmp/ansible-tmp-1623850968.0569956-41330-84151850272497/AnsiballZ_zabbix_template.py", line 40, in invoke_module
    runpy.run_module(mod_name='ansible.modules.monitoring.zabbix.zabbix_template', init_globals=None, run_name='__main__', alter_sys=True)
  File "/usr/lib/python3.8/runpy.py", line 207, in run_module
    return _run_module_code(code, init_globals, run_name, mod_spec)
  File "/usr/lib/python3.8/runpy.py", line 97, in _run_module_code
    _run_code(code, mod_globals, init_globals,
  File "/usr/lib/python3.8/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/tmp/ansible_zabbix_template_payload_wtf0mcm6/ansible_zabbix_template_payload.zip/ansible/modules/monitoring/zabbix/zabbix_template.py", line 756, in <module>
  File "/tmp/ansible_zabbix_template_payload_wtf0mcm6/ansible_zabbix_template_payload.zip/ansible/modules/monitoring/zabbix/zabbix_template.py", line 739, in main
  File "/tmp/ansible_zabbix_template_payload_wtf0mcm6/ansible_zabbix_template_payload.zip/ansible/modules/monitoring/zabbix/zabbix_template.py", line 386, in check_template_changed
  File "/tmp/ansible_zabbix_template_payload_wtf0mcm6/ansible_zabbix_template_payload.zip/ansible/modules/monitoring/zabbix/zabbix_template.py", line 526, in filter_xml_template
TypeError: a bytes-like object is required, not 'str'
fatal: [apps.dev.ntv-tv.ru]: FAILED! => {
    "changed": false,
    "module_stderr": "Traceback (most recent call last):\n  File \"/home/iglazkov/.ansible/tmp/ansible-tmp-1623850968.0569956-41330-84151850272497/AnsiballZ_zabbix_template.py\", line 102, in <module>\n    _ansiballz_main()\n  File \"/home/iglazkov/.ansible/tmp/ansible-tmp-1623850968.0569956-41330-84151850272497/AnsiballZ_zabbix_template.py\", line 94, in _ansiballz_main\n    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\n  File \"/home/iglazkov/.ansible/tmp/ansible-tmp-1623850968.0569956-41330-84151850272497/AnsiballZ_zabbix_template.py\", line 40, in invoke_module\n    runpy.run_module(mod_name='ansible.modules.monitoring.zabbix.zabbix_template', init_globals=None, run_name='__main__', alter_sys=True)\n  File \"/usr/lib/python3.8/runpy.py\", line 207, in run_module\n    return _run_module_code(code, init_globals, run_name, mod_spec)\n  File \"/usr/lib/python3.8/runpy.py\", line 97, in _run_module_code\n    _run_code(code, mod_globals, init_globals,\n  File \"/usr/lib/python3.8/runpy.py\", line 87, in _run_code\n    exec(code, run_globals)\n  File \"/tmp/ansible_zabbix_template_payload_wtf0mcm6/ansible_zabbix_template_payload.zip/ansible/modules/monitoring/zabbix/zabbix_template.py\", line 756, in <module>\n  File \"/tmp/ansible_zabbix_template_payload_wtf0mcm6/ansible_zabbix_template_payload.zip/ansible/modules/monitoring/zabbix/zabbix_template.py\", line 739, in main\n  File \"/tmp/ansible_zabbix_template_payload_wtf0mcm6/ansible_zabbix_template_payload.zip/ansible/modules/monitoring/zabbix/zabbix_template.py\", line 386, in check_template_changed\n  File \"/tmp/ansible_zabbix_template_payload_wtf0mcm6/ansible_zabbix_template_payload.zip/ansible/modules/monitoring/zabbix/zabbix_template.py\", line 526, in filter_xml_template\nTypeError: a bytes-like object is required, not 'str'\n",
    "module_stdout": "",
    "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error",
    "rc": 1
}

<!--- Paste verbatim command output between quotes -->
vanohaker commented 3 years ago

found a solution in your git https://github.com/ansible-collections/community.zabbix/blob/9c4fdc3f2a65b58ef201dfacb8be568a1219191a/plugins/modules/zabbix_template.py#L533