Open Vanav opened 1 year ago
I was able to reproduce this issue. This issue is related to special local Ansible configurations. This issue is triggered when working with Python virtualenvs. OP is working with virtualenv as can be seen by the python location /opt/pipx/venvs/ansible/bin/python
How to reproduce:
Solution:
When working with delegate_to
unexpected things happen to the ansible_python_interpreter. Please set the following environment variable to fix the issue.
export ANSIBLE_PYTHON_INTERPRETER="$(which python)"
To find out what is going on, you need to open the zabbix_group.py file in your installed zabbix collection and replace the very unhelpful code. Current code:
try:
from zabbix_api import Already_Exists
HAS_ZABBIX_API = True
ZBX_IMP_ERR = Exception()
except ImportError:
ZBX_IMP_ERR = traceback.format_exc()
HAS_ZABBIX_API = False
Replace it with this:
from zabbix_api import Already_Exists
If you run the playbook again, you will get a new error which shows you that Ansible is using a different Python environment where the python package zabbix-api
is not installed!
I can't tell which Ansible versions are affected. This fascinating behaviour cannot be fixed inside the the zabbix collection. However, it would be helpful to let the zabbix modules fail if python package zabbix-api
cannot be found.
zabbix_group fails in check mode, if host group is not existing yet.
Task:
Command:
ansible-playbook site.yml -l prod_hosts --check -vvv
Result:
TASK [zabbix : API | Create host groups] [CHECK MODE] **** task path: /srv/Projects/example.com/infra/roles/zabbix/tasks/main.yml:157 redirecting (type: connection) ansible.builtin.httpapi to ansible.netcommon.httpapi redirecting (type: modules) ansible.builtin.zabbix_group to community.zabbix.zabbix_group redirecting (type: modules) ansible.builtin.zabbix_group to community.zabbix.zabbix_group Using module file /opt/pipx/venvs/ansible/lib/python3.10/site-packages/ansible_collections/community/zabbix/plugins/modules/zabbix_group.py Pipelining is enabled.