Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KeyError: 'proxy_hostid' community.zabbix.zabbix_host #1163

Closed
Midas1989 opened this issue Jan 12, 2024 · 5 comments · Fixed by #1168
Closed

KeyError: 'proxy_hostid' community.zabbix.zabbix_host #1163

Midas1989 opened this issue Jan 12, 2024 · 5 comments · Fixed by #1168
Labels
bug Something isn't working

Comments

@Midas1989
Copy link

When you have subgroups in zabbix
image

You become an error when you override a host information

TASK [Remove all groups from the host] *****************************************************************************************************************************************************************************************************************************************************
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: KeyError: 'proxy_hostid'
fatal: [server1]: FAILED! => {"changed": false, "module_stderr": "Traceback (most recent call last):\n File "/home/users/ata0258253/.ansible/tmp/ansible-local-974097red6ju3e/ansible-tmp-1705068150.160186-976173-241943272178657/AnsiballZ_zabbix_host.py", line 107, in \n _ansiballz_main()\n File "/home/users/ata0258253/.ansible/tmp/ansible-local-974097red6ju3e/ansible-tmp-1705068150.160186-976173-241943272178657/AnsiballZ_zabbix_host.py", line 99, in _ansiballz_main\n invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\n File "/home/users/ata0258253/.ansible/tmp/ansible-local-974097red6ju3e/ansible-tmp-1705068150.160186-976173-241943272178657/AnsiballZ_zabbix_host.py", line 47, in invoke_module\n runpy.run_module(mod_name='ansible_collections.community.zabbix.plugins.modules.zabbix_host', init_globals=dict(_module_fqn='ansible_collections.community.zabbix.plugins.modules.zabbix_host', _modlib_path=modlib_path),\n File "", line 226, in run_module\n File "", line 98, in _run_module_code\n File "", line 88, in _run_code\n File "/tmp/ansible_community.zabbix.zabbix_host_payload_vtcm06jk/ansible_community.zabbix.zabbix_host_payload.zip/ansible_collections/community/zabbix/plugins/modules/zabbix_host.py", line 1250, in \n File "/tmp/ansible_community.zabbix.zabbix_host_payload_vtcm06jk/ansible_community.zabbix.zabbix_host_payload.zip/ansible_collections/community/zabbix/plugins/modules/zabbix_host.py", line 1093, in main\nKeyError: 'proxy_hostid'\n", "module_stdout": "", "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error", "rc": 1}
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: KeyError: 'proxy_hostid'

@BGmot
Copy link
Collaborator

BGmot commented Jan 12, 2024

Please submit Ansible code you used to get this error.

@Midas1989
Copy link
Author

Midas1989 commented Jan 12, 2024

THis one

- name: Remove all groups from the host
  vars:
    ansible_network_os: community.zabbix.zabbix
    ansible_connection: httpapi
    ansible_httpapi_port: 443
    ansible_httpapi_use_ssl: true
    ansible_httpapi_validate_certs: false
    ansible_host: "{{ zabbix_url }}"
    ansible_zabbix_url_path: ""
  community.zabbix.zabbix_host:
    host_name: "{{ ansible_facts['hostname'] }}"
    host_groups: []

or this one

- name: Create a new host or rewrite an existing host's info
  vars:
    ansible_network_os: community.zabbix.zabbix
    ansible_connection: httpapi
    ansible_httpapi_port: 443
    ansible_httpapi_use_ssl: true
    ansible_httpapi_validate_certs: false
    ansible_host: "{{ zabbix_url }}"
    ansible_zabbix_url_path: ""
  become: false
  community.zabbix.zabbix_host:
    host_name: "{{ ansible_facts['hostname'] }}"
    host_groups: "{{ hostgroups }}"
    link_templates: "{{ ansible_facts['link_templates'] }}"
    status: enabled
    state: present
    inventory_mode: manual
    interfaces:
      - type: 1
        main: 1
        useip: 1
        ip: "{{ ansible_facts['default_ipv4']['address'] }}"
        dns: "{{ ansible_facts['fqdn'] }}"
        port: "10050"
    proxy: "{{ zabbix_proxy }}"
    description: "{{ ansible_facts['ansible_local']['DESC'] }}"
    tags: "{{ combined_tags }}"
    tls_accept: 2
    tls_connect: 2
    tls_psk: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
    tls_psk_identity: "xxxxxxxxxxxx"
  delegate_to: localhost

both have the same problem, when in the existing host object store the following groups
image

When the existing host have this groups
image

The jobs running without problems.

Also when i create new hosts with groups and subgroups with the playbook
image

the first time the job is running without problems, the second run have the error

@BGmot
Copy link
Collaborator

BGmot commented Jan 12, 2024

Thank you. By the way groups: cannot be empty list.

@Midas1989
Copy link
Author

Midas1989 commented Jan 22, 2024

Hello @BGmot

Sorry but the problem ist also with filled groups.

Please read the issue

I can create hosts inital without problems (also with subgroups in the list), on the second run i have the issue.
Only the created group have subgroups in the groups.

Update:
The problem is only when groups are linked over the Playbook before.
It is not relevant whether they are normal groups or subgroups
When i add by the playbook a additional group by the second run, the second run is also successfull
When i add or remove a group on a host over the UI, the second run is also succesfu ll
Only when the groups for a host on the playbook and on zabbix is the same, i become the error

@Midas1989
Copy link
Author

Midas1989 commented Jan 22, 2024

My Workaround

- name: Search HostID
  uri:
    url: "{{ zabbix_url_full }}"
    method: POST
    body_format: json
    headers:
      Content-Type: "application/json"
    body:
      jsonrpc: "2.0"
      method: "host.get"
      params:
        filter:
          host: "{{ ansible_facts['hostname'] }}"
      auth: "{{ ansible_zabbix_auth_key }}"
      id: 2
  register: host_info
  delegate_to: localhost

- name: Search GroupID for group all
  uri:
    url: "{{ zabbix_url_full }}"
    method: POST
    body_format: json
    headers:
      Content-Type: "application/json"
    body:
      jsonrpc: "2.0"
      method: "hostgroup.get"
      params:
        output: "extend"
        filter:
          name: "all"
      auth: "{{ ansible_zabbix_auth_key }}"
      id: 2
  register: group_info
  delegate_to: localhost

- name: Remove groups from the host in Zabbix
  uri:
    url: "{{ zabbix_url_full }}"
    method: POST
    body_format: json
    body:
      jsonrpc: "2.0"
      method: "host.update"
      params:
        hostid: "{{ host_info.json.result[0].hostid }}"
        groups:
          - groupid: "{{ group_info.json.result[0].groupid }}"
      auth: "{{ ansible_zabbix_auth_key }}"
      id: 1
    headers:
      Content-Type: "application/json"
  register: response
  delegate_to: localhost

- name: Create a new host or rewrite an existing host's info
  vars:
    ansible_network_os: community.zabbix.zabbix
    ansible_connection: httpapi
    ansible_httpapi_port: 443
    ansible_httpapi_use_ssl: true
    ansible_httpapi_validate_certs: false
    ansible_host: "{{ zabbix_url }}"
    ansible_zabbix_url_path: ""
  become: false
  community.zabbix.zabbix_host:
    host_name: "{{ ansible_facts['hostname'] }}"
    visible_name: "{{ ansible_facts['hostname'] }}"
    host_groups: "{{ hostgroups }}"
    link_templates: "{{ ansible_facts['link_templates'] }}"
    status: enabled
    state: present
    inventory_mode: automatic
    interfaces:
      - type: 1
        main: 1
        useip: 1
        ip: "{{ ansible_facts['default_ipv4']['address'] }}"
        dns: "{{ ansible_facts['fqdn'] }}"
        port: "10050"
    proxy: "{{ zabbix_proxy }}"
    tags: "{{ combined_tags }}"
  delegate_to: localhost

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants