ansible-collections / community.zabbix

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

Unable to load API plugin for platform type community.zabbix #987

Closed exactoph closed 11 months ago

exactoph commented 1 year ago
SUMMARY

When using the example code from https://docs.ansible.com/ansible/latest/collections/community/zabbix/zabbix_host_module.html to use the host module, a error "unable to load API plugin for platform type community.zabbix" appears.

ISSUE TYPE
COMPONENT NAME

community.zabbix.zabbix httpapi

ANSIBLE VERSION
ansible [core 2.14.5]
  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.9/dist-packages/ansible
  ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/local/bin/ansible
  python version = 3.9.2 (default, Feb 28 2021, 17:03:44) [GCC 10.2.1 20210110] (/usr/bin/python3)
  jinja version = 3.1.2
  libyaml = True
CONFIGURATION
CONFIG_FILE() = /etc/ansible/ansible.cfg
HOST_KEY_CHECKING(/etc/ansible/ansible.cfg) = False
OS / ENVIRONMENT / Zabbix Version

OS: Debian 11 Zabbix: 6.4.2 Zabbix Collection: 2.0.0 Zabbix API: 0.5.6

STEPS TO REPRODUCE
- name: Test Zabbix plugin
  hosts: all

  tasks:

  # Set following variables for Zabbix Server host in play or inventory
  - name: Set connection specific variables
    set_fact:
      ansible_network_os: community.zabbix.zabbix
      ansible_connection: httpapi
      ansible_httpapi_port: 443
      ansible_httpapi_use_ssl: true
      ansible_httpapi_validate_certs: false
      ansible_zabbix_url_path: ""
    when: inventory_hostname in groups["zabbix"]

  # If you want to use Username and Password to be authenticated by Zabbix Server
  - name: Set credentials to access Zabbix Server API
    set_fact:
      ansible_user: "ansible"
      ansible_httpapi_pass: "..."
    delegate_to: "{{ zabbix_host }}"

  ##### Add Zabbix agent on Zabbix server
  - name: create host in Zabbix
    community.zabbix.zabbix_host:
      host_name: "testhost.example.com"
      host_groups:
       - Linux servers
      link_templates:
       - Linux by Zabbix agent

      interfaces:
          - type: 1
            main: 1
            useip: 1
            ip: "127.0.0.1"
            dns: "testhost.example.com"
            port: 10050
    delegate_to: "{{ zabbix_host }}"
EXPECTED RESULTS

New host "testhost.example.com" is created in zabbix.

ACTUAL RESULTS

API plugin cannot be loaded. No connection to zabbix can be established.
Not sure if this is the correct way, but it seems that the file plugins/httpapi/zabbix.py needs to be in the directory plugins/connection.
At least that worked for me, can't estimate if there are any side effects.

fatal: [...]: FAILED! => {"msg": "unable to load API plugin for network_os community.zabbix.zabbix"}
UserPiotr commented 1 year ago

Hi @exactoph , I had the same problem until I completely removed the collection and reinstalled as well as all requirements.