community.zabbix.zabbix_trigger module – Create/delete Zabbix triggers
Note
This module is part of the community.zabbix collection (version 3.3.0).
You might already have this collection installed if you are using the ansible package.
It is not included in ansible-core.
To check whether it is installed, run ansible-galaxy collection list.
To install it, use: ansible-galaxy collection install community.zabbix.
You need further requirements to be able to use this module,
see Requirements for details.
To use it in a playbook, specify: community.zabbix.zabbix_trigger.
Synopsis
- Create triggers if they do not exist. 
- Delete existing triggers if they exist. 
Requirements
The below requirements are needed on the host that executes this module.
- python >= 2.6 
Parameters
| Parameter | Comments | 
|---|---|
| list of triggers that this trigger is dependent on | |
| Name of host containing dependent trigger. Required when template_name is not used. Mutually exclusive with template_name. | |
| Name of dependent trigger. | |
| Name of template containing dependent trigger. Required when host_name is not used. Mutually exclusive with host_name. | |
| Additional description of the trigger. Overrides “comments” in API docs. | |
| Name of host to add trigger to. Required when template_name is not used. Mutually exclusive with template_name. | |
| Basic Auth password | |
| Basic Auth login | |
| Name of trigger to create or delete. Overrides “description” in API docs. Cannot be changed. If a trigger’s name needs to be changed, it needs to deleted and recreated | |
| Parameters to create/update trigger with. Required if state is “present”. Parameters as defined at https://www.zabbix.com/documentation/current/en/manual/api/reference/trigger/object Additionally supported parameters are below. | |
| OK event closes. Overrides “correlation_mode” in API docs. Choices: 
 | |
| Status of the trigger. Overrides “status” in API docs. Choices: 
 | |
| Whether the trigger can generate multiple problem events. Alias for “type” in API docs. Choices: 
 | |
| Allow manual close. Overrides “manual_close” in API docs. Choices: 
 | |
| New name for trigger | |
| OK event generation mode. Overrides “recovery_mode” in API docs. Choices: 
 | |
| Severity of the trigger. Alias for “priority” in API docs. Choices: 
 | |
| Status of the trigger. Choices: 
 | |
| Create or delete trigger. Choices: 
 | |
| Name of template to add trigger to. Required when host_name is not used. Mutually exclusive with host_name. | 
Examples
# If you want to use Username and Password to be authenticated by Zabbix Server
- name: Set credentials to access Zabbix Server API
  ansible.builtin.set_fact:
    ansible_user: Admin
    ansible_httpapi_pass: zabbix
# If you want to use API token to be authenticated by Zabbix Server
# https://www.zabbix.com/documentation/current/en/manual/web_interface/frontend_sections/administration/general#api-tokens
- name: Set API token
  ansible.builtin.set_fact:
    ansible_zabbix_auth_key: 8ec0d52432c15c91fcafe9888500cf9a607f44091ab554dbee860f6b44fac895
# Create ping trigger on example_host
- name: create ping trigger
  # set task level variables as we change ansible_connection plugin here
  vars:
    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: 'zabbixeu'  # If Zabbix WebUI runs on non-default (zabbix) path ,e.g. http://<FQDN>/zabbixeu
    ansible_host: zabbix-example-fqdn.org
  community.zabbix.zabbix_trigger:
    name: agent_ping
    host_name: example_host
    params:
        severity: high
        expression: 'nodata(/example_host/agent.ping,1m)=1'
        manual_close: True
        enabled: True
    state: present
# Create ping trigger on example_template
- name: create ping trigger
  # set task level variables as we change ansible_connection plugin here
  vars:
    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: 'zabbixeu'  # If Zabbix WebUI runs on non-default (zabbix) path ,e.g. http://<FQDN>/zabbixeu
    ansible_host: zabbix-example-fqdn.org
  community.zabbix.zabbix_trigger:
    name: agent_ping
    host_name: example_template
    params:
        severity: high
        expression: 'nodata(/example_template/agent.ping,1m)=1'
        manual_close: True
        enabled: True
    state: present
# Add tags to the existing Zabbix trigger
- name: update ping trigger
  # set task level variables as we change ansible_connection plugin here
  vars:
    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: 'zabbixeu'  # If Zabbix WebUI runs on non-default (zabbix) path ,e.g. http://<FQDN>/zabbixeu
    ansible_host: zabbix-example-fqdn.org
  community.zabbix.zabbix_trigger:
    name: agent_ping
    host_name: example_template
    params:
        severity: high
        expression: 'nodata(/example_template/agent.ping,1m)=1'
        manual_close: True
        enabled: True
        tags:
          - tag: class
            value: application
    state: present
# delete Zabbix trigger
- name: delete ping trigger
  # set task level variables as we change ansible_connection plugin here
  vars:
    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: 'zabbixeu'  # If Zabbix WebUI runs on non-default (zabbix) path ,e.g. http://<FQDN>/zabbixeu
    ansible_host: zabbix-example-fqdn.org
  community.zabbix.zabbix_trigger:
    name: agent_ping
    host_name: example_template
    state: absent
- name: Rename Zabbix trigger
  # set task level variables as we change ansible_connection plugin here
  vars:
    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: "zabbixeu"  # If Zabbix WebUI runs on non-default (zabbix) path ,e.g. http://<FQDN>/zabbixeu
    ansible_host: zabbix-example-fqdn.org
  community.zabbix.zabbix_trigger:
    name: agent_ping
    template_name: example_template
    params:
      new_name: new_agent_ping
    state: present
