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: 'inventory_mode' when updating existing host via zabbix_agent role #385

Closed
Tracked by #392
tambetliiv opened this issue May 26, 2021 · 10 comments · Fixed by #415
Closed
Tracked by #392

KeyError: 'inventory_mode' when updating existing host via zabbix_agent role #385

tambetliiv opened this issue May 26, 2021 · 10 comments · Fixed by #415
Labels
bug Something isn't working module The issue or pull request is related to Zabbix module

Comments

@tambetliiv
Copy link

SUMMARY

After zabbix server upgrade to 5.4.0 updating existing host data fails with error:

KeyError: 'inventory_mode'
ISSUE TYPE
  • Bug Report
COMPONENT NAME

Module: zabbix_host.py

ANSIBLE VERSION
❯ ansible --version
ansible 2.10.10
  config file = /home/<omitted>/ansible.cfg
  configured module search path = ['/home/<omitted>/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /home/<omitted>/.local/lib/python3.8/site-packages/ansible
  executable location = /home/<omitted>/.local/bin/ansible
  python version = 3.8.5 (default, Jan 27 2021, 15:41:15) [GCC 9.3.0]
CONFIGURATION
❯ ansible-config dump --only-changed
ANSIBLE_PIPELINING(/home/<omitted_path>/ansible.cfg) = True
ANSIBLE_SSH_ARGS(/home/<omitted_path>/ansible.cfg) = -o ForwardAgent=yes -o ControlMaster=auto -o ControlPersist=60s
ANSIBLE_SSH_CONTROL_PATH(/home/<omitted_path>/ansible.cfg) = %(directory)s/%%C
DEFAULT_CALLBACK_WHITELIST(/home/<omitted_path>/ansible.cfg) = ['profile_tasks', 'timer']
DEFAULT_HOST_LIST(/home/<omitted_path>/ansible.cfg) = ['/home/<omitted_path>/servers']
DEFAULT_ROLES_PATH(/home/<omitted_path>/ansible.cfg) = ['/home/<omitted_path>/roles']
DEFAULT_TIMEOUT(/home/<omitted_path>/ansible.cfg) = 60
DEFAULT_VARS_PLUGIN_PATH(/home/<omitted_path>/ansible.cfg) = ['/home/<omitted_path>/vars_plugins']
HOST_KEY_CHECKING(/home/<omitted_path>/ansible.cfg) = False
TRANSFORM_INVALID_GROUP_CHARS(/home/<omitted_path>/ansible.cfg) = ignore
OS / ENVIRONMENT / Zabbix Version

Zabbix server: zabbix/zabbix-server-pgsql:alpine-5.4.0

Target machine which host data to be updated:

target-host $ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 18.04.5 LTS
Release:        18.04
Codename:       bionic
STEPS TO REPRODUCE
  1. Install ansible, sshpass, docker and docker-compose
  2. git clone [email protected]:tambetliiv/ansible-zabbix-debug.git
  3. cd ansible-zabbix-debug
  4. docker-compose up -d
  5. ansible-playbook main.yml -i servers -u root -k use ssh password root
  6. First run (host adding) should succeed.
  7. Run ansible-playbook main.yml -i servers -u root -k second time and this KeyError will occur.
EXPECTED RESULTS

Playbook should succeed in update existing host info

ACTUAL RESULTS
TASK [community.zabbix.zabbix_agent : API | Create a new host or update an existing host's info] ****************************************************************************************************************************************
task path: /home/<omitted>/.ansible/collections/ansible_collections/community/zabbix/roles/zabbix_agent/tasks/api.yml:35
Wednesday 26 May 2021  11:09:23 +0000 (0:00:00.071)       0:00:22.254 *********
Using module file /home/<omitted>/.ansible/collections/ansible_collections/community/zabbix/plugins/modules/zabbix_host.py
Pipelining is enabled.
<localhost> ESTABLISH LOCAL CONNECTION FOR USER: <omitted>
<localhost> EXEC /bin/sh -c '/usr/bin/python3 && sleep 0'
FAILED - RETRYING: API | Create a new host or update an existing host's info (3 retries left).Result was: {
    "attempts": 1,
    "changed": false,
    "module_stderr": "Traceback (most recent call last):\n  File \"<stdin>\", line 102, in <module>\n  File \"<stdin>\", line 94, in _ansiballz_main\n  File \"<stdin>\", line 40, in invoke_module\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_host_payload__pi28va6/ansible_zabbix_host_payload.zip/ansible_collections/community/zabbix/plugins/modules/zabbix_host.py\", line 1205, in <module>\n  File \"/tmp/ansible_zabbix_host_payload__pi28va6/ansible_zabbix_host_payload.zip/ansible_collections/community/zabbix/plugins/modules/zabbix_host.py\", line 1151, in main\n  File \"/tmp/ansible_zabbix_host_payload__pi28va6/ansible_zabbix_host_payload.zip/ansible_collections/community/zabbix/plugins/modules/zabbix_host.py\", line 774, in check_all_properties\nKeyError: 'inventory_mode'\n",
    "module_stdout": "",
    "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error",
    "rc": 1,
    "retries": 4
}
@tambetliiv tambetliiv changed the title KeyError: 'inventory_mode' when updating existing host KeyError: 'inventory_mode' when updating existing host via zabbix_agent role May 26, 2021
@D3DeFi D3DeFi added bug Something isn't working module The issue or pull request is related to Zabbix module labels May 28, 2021
@D3DeFi
Copy link
Contributor

D3DeFi commented May 28, 2021

Thank you for reporting this @tambetliiv . I will try to look into it more closer over the weekend

@D3DeFi D3DeFi mentioned this issue May 29, 2021
10 tasks
@tambetliiv
Copy link
Author

Any current workaround, because for now our regular zabbix playbook fails and some quick fix would be appreciated until more permanent one is released.

@tambetliiv
Copy link
Author

ping @D3DeFi would really like a fix or some workaround. Currently our envs zabbix playbook is broken because of this bug. Can't update any existing host info.

@dsteinkopf
Copy link

I am also experiencing a very similar (or same?) problem since upgrading to 5.4:

FAILED - RETRYING: Create a new host or update an existing host's info (3 retries left).
FAILED - RETRYING: Create a new host or update an existing host's info (2 retries left).
FAILED - RETRYING: Create a new host or update an existing host's info (1 retries left).
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: KeyError: 'inventory_mode'
fatal: [myhost -> localhost]: FAILED! => {"attempts": 3, "changed": false, "module_stderr": "Traceback (most recent call last):
  File \"/root/.ansible/tmp/ansible-tmp-1623646155.1850684-24933348306129/AnsiballZ_zabbix_host.py\", line 102, in <module>
    _ansiballz_main()
  File \"/root/.ansible/tmp/ansible-tmp-1623646155.1850684-24933348306129/AnsiballZ_zabbix_host.py\", line 94, in _ansiballz_main
    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)
  File \"/root/.ansible/tmp/ansible-tmp-1623646155.1850684-24933348306129/AnsiballZ_zabbix_host.py\", line 40, in invoke_module
    runpy.run_module(mod_name='ansible_collections.community.zabbix.plugins.modules.zabbix_host', 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_host_payload_vmw3x52r/ansible_zabbix_host_payload.zip/ansible_collections/community/zabbix/plugins/modules/zabbix_host.py\", line 1203, in <module>
  File \"/tmp/ansible_zabbix_host_payload_vmw3x52r/ansible_zabbix_host_payload.zip/ansible_collections/community/zabbix/plugins/modules/zabbix_host.py\", line 1150, in main
  File \"/tmp/ansible_zabbix_host_payload_vmw3x52r/ansible_zabbix_host_payload.zip/ansible_collections/community/zabbix/plugins/modules/zabbix_host.py\", line 774, in check_all_properties
KeyError: 'inventory_mode'
", "module_stdout": "", "msg": "MODULE FAILURE
See stdout/stderr for the exact error", "rc": 1}

@D3DeFi
Copy link
Contributor

D3DeFi commented Jun 14, 2021

@tambetliiv feel free to get to the bottom of this and prepare a pull request or document workaround for others. Since this is an open source community, any contribution is welcome. I, unfortunately, really don't have time to work on this right now.

Zabbix doesn't have proper API as they are changing things left and right in each release without proper deprecation or anything and we are just not able to keep up with it proactively as there are already so few of us still maintaining these modules in our free time.

I can give just pointers from what I've observed before:

  • there is no inventory_mode returned in API call host.get
  • module works when inventory_mode module parameter is not set (<- workaround?)
  • ansible-test integration test_zabbix_host is also able to reproduce this bug

Why this started happening? Did Zabbix developers released a bugged version? Since there is no information relating deprecation of this key in https://www.zabbix.com/documentation/current/manual/api/changes_5.4. or does this mean that Zabbix developers no longer wants us to configure behavior of inventory for Zabbix hosts?

Same problem is happening in the issue regarding zabbix_template, Zabbix just changed behavior of API and it no longer does what it is supposed to be doing.

@sky-joker would you perhaps have some time to look into this more?

@tambetliiv
Copy link
Author

tambetliiv commented Jun 14, 2021

@D3DeFi, I reached to about the same conclusion. Created issue to zabbix support. Lets see what they have to say about this. Hopefully bug, that will be fixed quickly, but never know.

tambetliiv added a commit to tambetliiv/community.zabbix that referenced this issue Jun 14, 2021
@tambetliiv
Copy link
Author

Created very very dirty workaround which is ok for our env, since most hosts/all have inventory_mode set to 0 anyway.

@mprenditore
Copy link

Created very very dirty workaround which is ok for our env, since most hosts/all have inventory_mode set to 0 anyway.

I'm experiencing the same issue after upgrading the server to 5.4. How can I start to use this updated file?
My folder structure is:

ansible
  |_ roles
  | |_ zabbix_agent
  |_ setup_zabbix_agent_playbook.yml

@mprenditore
Copy link

found it, just created a folder library inside the role and put inside the fixed module from @tambetliiv
Thanks for the workaround!

@laurence-syree
Copy link
Contributor

It seems the reason for this is that on Zabbix 5.4 when you call the API for a host it no longer includes the inventory_host field. According to people on the Zabbix support page @tambetliiv raised, this is a bug and will be fixed in future versions however it still leaves 5.4 with this issue. I managed to get around this by adding a rule on the "get_host_by_host_name" function which requests the fields explicitly rather than asking for "all" which is bugged when using version 5.4.

I will see about getting a fork of the repo for this, however, I'm not super familiar with the contributing process. Feel free to PM me if you require this fix now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working module The issue or pull request is related to Zabbix module
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants