1

I have an issue with the conversion (migration) from zabbix 6.0 to zabbix 6.2. I have a playbook in Ansible to automatically add a host to zabbix with some host_groups and Templates predefined which worked on Zabbix 6.0 but in 6.2 zabbix added the Template_groups and now the playbook complains that it can't find the templates anymore.

Here is a part of the playbook:

- name: ZABBIX - Create or update host
  local_action:
    module: community.zabbix.zabbix_host
    server_url: https://monitor.localdomain
    login_user: "a*******a"
    login_password: "S*********************y"
    host_name: "{{ ansible_hostname }}"
    visible_name: "{{ ansible_hostname }}"
    tls_psk_identity: "{{ ansible_hostname }}"
    tls_accept: 2
    tls_connect: 2
    tls_psk: "{{ psk.stdout }}"
    host_groups:
      - Linux servers
    link_templates:
      - Template OS Linux
      - Template YUM Updates
    status: enabled
    state: present
    inventory_mode: automatic
    interfaces:
      - type: 1
        main: 1
        useip: 1
        ip: "{{ ansible_default_ipv4.address }}"
      - type: 2
        main: 1
        useip: 1
        ip: "{{ ansible_default_ipv4.address }}"
        details:
          community: "{$SNMP_COMMUNITY}"
          version: 2
    proxy: "ZabbixProxy"
  vars:
    ansible_python_interpreter: "/usr/bin/python3"
  tags:
    - zabbix-agent

This worked perfectly on 6.0 and added the servers to the host_group Linux Servers and added the templates OS Linux and YUM updates with no issue.

Now in 6.2 it complains that it can't find the templates, and if I outhash the templates it complains that it can't find the host_group. When I outhash that it complains that it has to have at least 1 host group.... :|

I tried all combinations of templates, as the templates are now in the template group: "Templates/Operating Systems" I even added a template_groups: section in the playbook as that is a valid field in rust, but apparently it is not for ansible as now it complains on a invalid module found.

How do I change/add the templategroup the correct way...?

Thanks for reading and thinking along with me.

1 Answer 1

0

This is what worked for me, I used delegate_to to pass all request against zabbix API server. And let Ansible manage the loop/fork/parallel execution for each of the host in the group.

---

- name: Update hosts in Zabbix
  hosts: "{{ groups['role_ep'] }}"
  vars_files:
    - vars/main.yaml
  vars:
    ansible_network_os: community.zabbix.zabbix
    ansible_connection: httpapi
    server_url: "{{ zabbix_server.fqdn }}"
    ansible_zabbix_auth_key: "{{ zabbix_server.api_key }}"
    ansible_zabbix_url_path: ''  
  tasks:

    - name: Create a new host or rewrite an existing host's info
      become: false
      delegate_to: "{{ zabbix_server.fqdn }}"
      community.zabbix.zabbix_host:
        host_name: "{{ inventory_hostname }}"
        visible_name: "{{ inventory_hostname }}"
        description: "{{ inventory_hostname }}"
        host_groups:
          - Linux servers
        link_templates:
          - Linux by Zabbix agent
          - Chassis by IPMI
        status: enabled
        state: present
        inventory_mode: manual
        # inventory_zabbix:
        #   tag: "{{ your_tag }}"
        #   alias: "{{ your_alias }}"
        #   notes: "Special Informations: {{ your_informations | default('None') }}"
        #   location: "{{ your_location }}"
        #   site_rack: "{{ your_site_rack }}"
        #   os: "{{ your_os }}"
        #   hardware: "{{ your_hardware }}"
        ipmi_authtype: -1 # default
        ipmi_privilege: 3 # operator
        ipmi_username: "{{ ipmi_username }}"
        ipmi_password: "{{ ipmi_password }}"
        interfaces:
          - type: 1
            main: 1
            useip: 0
            ip: "{{ primaryIpAddress }}"
            dns: "{{ inventory_hostname }}"
            port: "10050"
          - type: 3
            main: 1
            useip: 1
            ip: "{{ networkManagementIpAddress }}"
            dns: ""
            port: "623"
        # proxy: a.zabbix.proxy
        # macros:
        #   - macro: "{$EXAMPLEMACRO}"
        #     value: ExampleMacroValue
        #   - macro: EXAMPLEMACRO2
        #     value: ExampleMacroValue2
        #     description: Example desc that work only with Zabbix 4.4 and higher
        # tags:
        #   - tag: ExampleHostsTag
        #   - tag: ExampleHostsTag2
        #     value: ExampleTagValue

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .