ansible-collections / community.zabbix

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

zabbix_template_info and zabbix_template modules fail with "connection error occurred: string indices must be integers" #1141

Closed dshuffin closed 11 months ago

dshuffin commented 11 months ago
SUMMARY

Running zabbix_template_info and zabbix_template modules fail with "connection error occurred: string indices must be integers". This seems to happen when template has value maps defined. Another requirement is that the module exports the template from zabbix, so running zabbix_template_info with format none doesn't trigger the error. Also importing the template for the first time using zabbix_template doesn't trigger the error, but re-running the same task again does.

ISSUE TYPE
COMPONENT NAME

zabbix_template_info

ANSIBLE VERSION
ansible [core 2.15.6]
  config file = /home/xxx/infrastructure/ansible.cfg
  configured module search path = ['/home/xxx/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3/dist-packages/ansible
  ansible collection location = /home/xxx/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/bin/ansible
  python version = 3.10.12 (main, Nov 20 2023, 15:14:05) [GCC 11.4.0] (/usr/bin/python3)
  jinja version = 3.0.3
  libyaml = True
CONFIGURATION
CONFIG_FILE() = /home/xxx/infrastructure/ansible.cfg
DEFAULT_LOAD_CALLBACK_PLUGINS(/home/xxx/infrastructure/ansible.cfg) = True
DEFAULT_MANAGED_STR(/home/xxx/infrastructure/ansible.cfg) = "$Ansible {{{{ template_path|basename + lookup('pipe', 'git log --format=",%%h %%ad %%ae" -1 --date=format:"%%Y-%%m-%%d %%H:%%M" ' + template_fullpath|quote)|default(>
DEFAULT_ROLES_PATH(/home/xxx/infrastructure/ansible.cfg) = ['/home/xxx/infrastructure/galaxy_roles', '/home/xxx/infrastructure/roles']
DEFAULT_STDOUT_CALLBACK(/home/xxx/infrastructure/ansible.cfg) = yaml
DEFAULT_TIMEOUT(/home/xxx/infrastructure/ansible.cfg) = 60
OS / ENVIRONMENT / Zabbix Version

Zabbix 6.0.23 Control node ubuntu 22.04.

STEPS TO REPRODUCE

export built-in template "APC UPS by SNMP" in json format using zabbix_template_info module

- name: Download Template
  tags: test
  community.zabbix.zabbix_template_info:
    template_name: "APC UPS by SNMP"
    format: json
EXPECTED RESULTS

exported template in json format

ACTUAL RESULTS
TASK [zabbix_templates : Download Template] *************************************************************************************************************************************************************************************************
task path: /home/xxx/infrastructure/roles/zabbix_templates/tasks/main.yml:35
redirecting (type: connection) ansible.builtin.httpapi to ansible.netcommon.httpapi
Loading collection ansible.netcommon from /usr/lib/python3/dist-packages/ansible_collections/ansible/netcommon
Loading collection ansible.utils from /usr/lib/python3/dist-packages/ansible_collections/ansible/utils
<hostname> attempting to start connection
<hostname> using connection plugin ansible.netcommon.httpapi
Found ansible-connection at path /usr/bin/ansible-connection
<hostname> found existing local domain socket, using it!
<hostname> updating play_context for connection
<hostname> Loading collection ansible.builtin from
<hostname> local domain socket path is /home/xxx/.ansible/pc/d5d6474ecc
<hostname> ESTABLISH LOCAL CONNECTION FOR USER: xxx
<hostname> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /home/xxx/.ansible/tmp/ansible-local-107907ztrb9f_x `"&& mkdir "` echo /home/xxx/.ansible/tmp/ansible-local-107907ztrb9f_x/ansible-tmp-1701711941.2163904-107934-240745331906759 `" && echo ansible-tmp-1701711941.2163904-107934-240745331906759="` echo /home/xxx/.ansible/tmp/ansible-local-107907ztrb9f_x/ansible-tmp-1701711941.2163904-107934-240745331906759 `" ) && sleep 0'
Using module file /usr/lib/python3/dist-packages/ansible_collections/community/zabbix/plugins/modules/zabbix_template_info.py
<hostname> PUT /home/xxx/.ansible/tmp/ansible-local-107907ztrb9f_x/tmpfqdcwf8w TO /home/xxx/.ansible/tmp/ansible-local-107907ztrb9f_x/ansible-tmp-1701711941.2163904-107934-240745331906759/AnsiballZ_zabbix_template_info.py
<hostname> EXEC /bin/sh -c 'chmod u+x /home/xxx/.ansible/tmp/ansible-local-107907ztrb9f_x/ansible-tmp-1701711941.2163904-107934-240745331906759/ /home/xxx/.ansible/tmp/ansible-local-107907ztrb9f_x/ansible-tmp-1701711941.2163904-107934-240745331906759/AnsiballZ_zabbix_template_info.py && sleep 0'
<hostname> EXEC /bin/sh -c '/usr/bin/python3 /home/xxx/.ansible/tmp/ansible-local-107907ztrb9f_x/ansible-tmp-1701711941.2163904-107934-240745331906759/AnsiballZ_zabbix_template_info.py && sleep 0'
<hostname> EXEC /bin/sh -c 'rm -f -r /home/xxx/.ansible/tmp/ansible-local-107907ztrb9f_x/ansible-tmp-1701711941.2163904-107934-240745331906759/ > /dev/null 2>&1 && sleep 0'
The full traceback is:
  File "/tmp/ansible_community.zabbix.zabbix_template_info_payload_7o9xjvz1/ansible_community.zabbix.zabbix_template_info_payload.zip/ansible_collections/community/zabbix/plugins/module_utils/api_request.py", line 29, in _httpapi_error_handle
    code, response = self.connection.send_request(data=payload)
  File "/tmp/ansible_community.zabbix.zabbix_template_info_payload_7o9xjvz1/ansible_community.zabbix.zabbix_template_info_payload.zip/ansible/module_utils/connection.py", line 200, in __rpc__
    raise ConnectionError(to_text(msg, errors='surrogate_then_replace'), code=code)
fatal: [hostname]: FAILED! => changed=false
  invocation:
    module_args:
      format: json
      http_login_password: null
      http_login_user: null
      omit_date: false
      template_name: APC UPS by SNMP
  msg: 'connection error occurred: string indices must be integers'
BGmot commented 11 months ago

Check this https://github.com/ansible-collections/community.zabbix/issues/1113 please.

dshuffin commented 11 months ago

Thank you, installing 2.2.0 from ansible-galaxy indeed fixed the issue. Any chance of getting 2.2.0 bundled into ansible package, as even the latest version 9.0.1 includes 2.1.0?

BGmot commented 11 months ago

This is weird indeed. That's probably because we still have "the latest" pointing to 2.1.0 https://github.com/ansible-collections/community.zabbix/releases. @pyrodie18 do you mind if I fix this? @dshuffin thanks for finding this inconsistency!

BGmot commented 11 months ago

fixed