ansible-collections / community.zabbix

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

"msg": "Host group not found: QA" even though the group does exist #1339

Closed Rom1nd closed 1 month ago

Rom1nd commented 1 month ago
SUMMARY

"msg": "Host group not found: QA" even though the group exists same problem with templates, for example: Linux by Zabbix agent

"msg": "Template not found: Linux by Zabbix agent"

ISSUE TYPE
COMPONENT NAME

community.zabbix.zabbix_host

ANSIBLE VERSION
ansible [core 2.17.1]
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/lib/python3.11/dist-packages/ansible
  ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/local/bin/ansible
  python version = 3.11.2 (main, May  2 2024, 11:59:08) [GCC 12.2.0] (/usr/bin/python3)
  jinja version = 3.1.2
  libyaml = True
CONFIGURATION
CONFIG_FILE() = /etc/ansible/ansible.cfg
DEFAULT_BECOME(/etc/ansible/ansible.cfg) = True
DEFAULT_BECOME_ASK_PASS(/etc/ansible/ansible.cfg) = False
DEFAULT_BECOME_USER(/etc/ansible/ansible.cfg) = root
DEFAULT_EXECUTABLE(/etc/ansible/ansible.cfg) = /bin/sh
DEFAULT_HOST_LIST(/etc/ansible/ansible.cfg) = ['/etc/ansible/hosts']
EDITOR(env: EDITOR) = nano
HOST_KEY_CHECKING(/etc/ansible/ansible.cfg) = False
PLAYBOOK_DIR(/etc/ansible/ansible.cfg) = /etc/ansible/playbook
OS / ENVIRONMENT / Zabbix Version

cat /etc/debian_version 12.6

Zabbix 7.0

STEPS TO REPRODUCE
---
- name: Ajouter l'hôte sur le serveur Zabbix
  hosts: pzabbix01v
  vars_files:
   - /etc/ansible/vault/secrets.yml

  tasks:

    - name: Set connection specific variables
      set_fact:
          ansible_network_os: community.zabbix.zabbix
          ansible_connection: httpapi
          ansible_httpapi_port: 80
          ansible_httpapi_use_ssl: false
          ansible_httpapi_validate_certs: false
          ansible_zabbix_url_path: ""
          zabbix_url: "http://zabbix.aut.fr/api_jsonrpc.php"
          ansible_user: "myzabbixuser"
          ansible_httpapi_pass: "mypassword"

    - set_fact: ip_host="{{ hostvars[qhaproxy01v]['ansible_host'] }}"

    - name: Debug
      debug:
        var: "{{ ip_host }}"

    - name: Ajouter l'hôte sur le serveur Zabbix avec des modèles QHAPROXY
      community.zabbix.zabbix_host:
        host_name: "qhaproxy01v"
        visible_name: "qhaproxy01v"
        description: Serveur Haproxy de QA test phpfpm
        host_groups:
          - "QA"
          - "haproxy"
        interfaces:
          - type: 1
            main: 1
            useip: 1
            ip: "{{ ip_host }}"
            port: 10050
        inventory_mode: automatic
        status: disabled
        state: present
        tls_connect: 2
        tls_accept: 2
        tls_psk_identity: "{{ psk_identity }}"
        tls_psk: "{{ psk_key }}"
      register: qhaproxy
      ignore_errors: true
      when: HOSTS in groups.get('qhaproxy', [])
EXPECTED RESULTS

I want my hosts to be added to the Zabbix inventory with its models and groups

ACTUAL RESULTS

I currently have this error message: "msg": "Host group not found: QA"

18:22:52 ok: [pzabbix01v]
18:22:52 Read vars_file '/etc/ansible/vault/secrets.yml'
18:22:52 Read vars_file '/etc/ansible/vault/secrets.yml'
18:22:52 Read vars_file '/etc/ansible/vault/secrets.yml'
18:22:52 
18:22:52 TASK [Set connection specific variables] ***************************************
18:22:52 task path: /etc/ansible/playbooksys/templatedebian/configurationzabbixagent3.yml:9
18:22:52 ok: [pzabbix01v] => {
18:22:52     "ansible_facts": {
18:22:52         "ansible_connection": "httpapi",
18:22:52         "ansible_httpapi_pass": "myzabbixpassword",
18:22:52         "ansible_httpapi_port": 80,
18:22:52         "ansible_httpapi_use_ssl": false,
18:22:52         "ansible_httpapi_validate_certs": false,
18:22:52         "ansible_network_os": "community.zabbix.zabbix",
18:22:52         "[*******]": "[*******]",
18:22:52         "ansible_zabbix_url_path": "",
18:22:52         "zabbix_url": "http://zabbix.aut.fr/api_jsonrpc.php"
18:22:52     },
18:22:52     "changed": false
18:22:52 }
18:22:52 Read vars_file '/etc/ansible/vault/secrets.yml'
18:22:52 
18:22:52 TASK [set_fact] ****************************************************************
18:22:52 task path: /etc/ansible/playbooksys/templatedebian/configurationzabbixagent3.yml:21
18:22:52 redirecting (type: connection) ansible.builtin.httpapi to ansible.netcommon.httpapi
18:22:52 ok: [pzabbix01v] => {
18:22:52     "ansible_facts": {
18:22:52         "ip_host": "172.30.10.65"
18:22:52     },
18:22:52     "changed": false
18:22:52 }
18:22:52 Read vars_file '/etc/ansible/vault/secrets.yml'
18:22:52 
18:22:52 TASK [Debug] *******************************************************************
18:22:52 task path: /etc/ansible/playbooksys/templatedebian/configurationzabbixagent3.yml:23
18:22:52 redirecting (type: connection) ansible.builtin.httpapi to ansible.netcommon.httpapi
18:22:52 ok: [pzabbix01v] => {
18:22:52     "172.30.10.65": "VARIABLE IS NOT DEFINED!: float object has no element 10"
18:22:52 }
18:22:52 Read vars_file '/etc/ansible/vault/secrets.yml'
18:22:52 
18:22:52 TASK [Ajouter l'hôte sur le serveur Zabbix avec des modèles QHAPROXY] **********
18:22:52 task path: /etc/ansible/playbooksys/templatedebian/configurationzabbixagent3.yml:27
18:22:53 redirecting (type: connection) ansible.builtin.httpapi to ansible.netcommon.httpapi
18:22:53 <172.30.0.5> ESTABLISH LOCAL CONNECTION FOR USER: root
18:22:53 <172.30.0.5> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /root/.ansible/tmp/ansible-local-4088058quw7rlu2 `"&& mkdir "` echo /root/.ansible/tmp/ansible-local-4088058quw7rlu2/ansible-tmp-1720628572.8506682-4088079-281034302257621 `" && echo ansible-tmp-1720628572.8506682-4088079-281034302257621="` echo /root/.ansible/tmp/ansible-local-4088058quw7rlu2/ansible-tmp-1720628572.8506682-4088079-281034302257621 `" ) && sleep 0'
18:22:53 Using module file /root/.ansible/collections/ansible_collections/community/zabbix/plugins/modules/zabbix_host.py
18:22:53 <172.30.0.5> PUT /root/.ansible/tmp/ansible-local-4088058quw7rlu2/tmpcckd0b05 TO /root/.ansible/tmp/ansible-local-4088058quw7rlu2/ansible-tmp-1720628572.8506682-4088079-281034302257621/AnsiballZ_zabbix_host.py
18:22:53 <172.30.0.5> EXEC /bin/sh -c 'chmod u+x /root/.ansible/tmp/ansible-local-4088058quw7rlu2/ansible-tmp-1720628572.8506682-4088079-281034302257621/ /root/.ansible/tmp/ansible-local-4088058quw7rlu2/ansible-tmp-1720628572.8506682-4088079-281034302257621/AnsiballZ_zabbix_host.py && sleep 0'
18:22:53 <172.30.0.5> EXEC /bin/sh -c 'sudo -H -S -n  -u root /bin/sh -c '"'"'echo BECOME-SUCCESS-qthvggokbglbqgjrcmmjiqzisgaroaqq ; /usr/bin/python3 /root/.ansible/tmp/ansible-local-4088058quw7rlu2/ansible-tmp-1720628572.8506682-4088079-281034302257621/AnsiballZ_zabbix_host.py'"'"' && sleep 0'
18:22:53 <172.30.0.5> EXEC /bin/sh -c 'rm -f -r /root/.ansible/tmp/ansible-local-4088058quw7rlu2/ansible-tmp-1720628572.8506682-4088079-281034302257621/ > /dev/null 2>&1 && sleep 0'
18:22:53 fatal: [pzabbix01v]: FAILED! => {
18:22:53     "changed": false,
18:22:53     "invocation": {
18:22:53         "module_args": {
18:22:53             "ca_cert": null,
18:22:53             "description": "Serveur Haproxy de QA test phpfpm",
18:22:53             "force": true,
18:22:53             "host_groups": [
18:22:53                 "QA",
18:22:53                 "haproxy"
18:22:53             ],
18:22:53             "host_name": "qhaproxy01v",
18:22:53             "http_login_password": null,
18:22:53             "http_login_user": null,
18:22:53             "interfaces": [
18:22:53                 {
18:22:53                     "details": {
18:22:53                         "authpassphrase": "",
18:22:53                         "authprotocol": 0,
18:22:53                         "bulk": 1,
18:22:53                         "community": "",
18:22:53                         "contextname": "",
18:22:53                         "privpassphrase": "",
18:22:53                         "privprotocol": 0,
18:22:53                         "securitylevel": 0,
18:22:53                         "securityname": "",
18:22:53                         "version": 2
18:22:53                     },
18:22:53                     "dns": null,
18:22:53                     "ip": "172.30.10.65",
18:22:53                     "main": 1,
18:22:53                     "port": "10050",
18:22:53                     "type": "1",
18:22:53                     "useip": 1
18:22:53                 }
18:22:53             ],
18:22:53             "inventory_mode": "automatic",
18:22:53             "inventory_zabbix": null,
18:22:53             "ipmi_authtype": null,
18:22:53             "ipmi_password": null,
18:22:53             "ipmi_privilege": null,
18:22:53             "ipmi_username": null,
18:22:53             "link_templates": null,
18:22:53             "macros": null,
18:22:53             "monitored_by": null,
18:22:53             "proxy": null,
18:22:53             "proxy_group": null,
18:22:53             "state": "present",
18:22:53             "status": "disabled",
18:22:53             "tags": null,
18:22:53             "tls_accept": 2,
18:22:53             "tls_connect": 2,
18:22:53             "tls_psk": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
18:22:53             "tls_psk_identity": "3570358b18",
18:22:53             "tls_subject": null,
18:22:53             "visible_name": "qhaproxy01v"
18:22:53         }
18:22:53     },
18:22:53     "msg": "Hostgroup not found: QA"
18:22:53 }
18:22:53 ...ignoring
18:22:53 Read vars_file '/etc/ansible/vault/secrets.yml'
18:22:53 Read vars_file '/etc/ansible/vault/secrets.yml'
18:22:53 Read vars_file '/etc/ansible/vault/secrets.yml'
18:22:53 Read vars_file '/etc/ansible/vault/secrets.yml'
18:22:53 
18:22:53 PLAY RECAP *********************************************************************
18:22:53 pzabbix01v                 : ok=5    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=1   
BGmot commented 1 month ago

You did not specify what version of collection you are using and in any case you are using it wrong mixing old approach when zabbix_url was in play and current one with httpapi connection plugin. Please take a look at the example on how to use this collection.

pyrodie18 commented 1 month ago

Also do you actually have the QA host_group configured somewhere?

pyrodie18 commented 1 month ago

No response heard. Closing ticket

Rom1nd commented 1 month ago

Hello, sorry I was a vacation, so the problem came from me, the user use to add the host did not have the right, good day