ansiblezabbixansible-inventory

ansible zabbix module - loop though templates


i'm having some issued with the ansible zabbix module. i'm trying to assign multiple templates to a single host.

my ansible code which doesn't work:

    - name: Create/update Zabbix host
[...]
        link_templates:
          - '{{ zabbix_templates }}'
[...]

code that works:

    - name: Create/update Zabbix host
[...]
        link_templates:
          - "Zabbix agent active"
          - "Linux by Zabbix agent"
[...]

inventory

all:
  hosts:
[...]
  children:
 [...]-cluster:
      hosts:
      [...]
      vars:
        kubernetes_cluster: yes
        cluster_name: [...]-cluster
        OS: ubuntu_22
        zabbix_templates:
          - Zabbix agent active
          - Linux by Zabbix agent
        zabbix_hostgroup: Linux servers

the task itself looks very similar to the sample provides here: https://docs.ansible.com/ansible/latest/collections/community/zabbix/zabbix_host_module.html * [...] = snipped, with real values it works

the error message i'm receiving:

fatal: [[...]]: FAILED! => {"changed": false, "msg": "Template not found: ['Zabbix agent active', 'Linux by Zabbix agent']"}

i've tried to "reformat" the list multiple times like - '{{ zabbix_templates | map("from_yaml") | list }}' and other ways, still no luck. i'm looking for a solution on how to list those vars properly


Solution

  • Your zabbix_templates variable is already a list, so you just need to pass it directly to link_templates:

    link_templates: '{{ zabbix_templates }}'