zabbix_template – create/delete/dump zabbix template

New in version 2.5.

Synopsis

  • create/delete/dump zabbix template

Requirements

The below requirements are needed on the host that executes this module.

  • python >= 2.6
  • zabbix-api >= 0.5.3

Parameters

Parameter Choices/Defaults Comments
clear_templates
-
List of templates cleared from the template.
see templates_clear in https://www.zabbix.com/documentation/3.0/manual/api/reference/template/update
http_login_password
-
added in 2.1
Basic Auth password
http_login_user
-
added in 2.1
Basic Auth login
link_templates
-
List of templates linked to the template.
login_password
- / required
Zabbix user password.
login_user
- / required
Zabbix user name.
macros
-
List of templates macro
server_url
- / required
URL of Zabbix server, with protocol (http or https). url is an alias for server_url.

aliases: url
state
-
    Choices:
  • present ←
  • absent
  • dump
state present create/update template, absent delete template
template_groups
-
List of template groups to create or delete.
template_json
-
JSON dump of template to import
template_name
- / required
Name of zabbix template
timeout
-
Default:
10
The timeout of API request (seconds).
validate_certs
boolean
added in 2.5
    Choices:
  • no
  • yes ←
If set to False, SSL certificates will not be validated. This should only be used on personally controlled sites using self-signed certificates.

Examples

---
# Creates a new zabbix template from linked template
- name: Create Zabbix template using linked template
  local_action:
    module: zabbix_template
    server_url: http://127.0.0.1
    login_user: username
    login_password: password
    template_name: ExampleHost
    template_json: "{'zabbix_export': {}}"
    template_groups:
      - Role
      - Role2
    link_templates:
      - Example template1
      - Example template2
    clear_templates:
      - Example template3
      - Example template4
    macros:
      - macro: '{$EXAMPLE_MACRO1}'
        value: 30000
      - macro: '{$EXAMPLE_MACRO2}'
        value: 3
      - macro: '{$EXAMPLE_MACRO3}'
        value: 'Example'
    state: present

# Create a new template from a json config definition
- name: Import Zabbix json template configuration
  local_action:
    module: zabbix_template
    server_url: http://127.0.0.1
    login_user: username
    login_password: password
    template_name: Apache2
    template_json: "{{ lookup('file', 'zabbix_apache2.json') }}"
    template_groups:
      - Webservers
    state: present

# Import a template from Ansible variable dict
- name: Import Zabbix Template
  zabbix_template:
    login_user: username
    login_password: password
    server_url: http://127.0.0.1
    template_name: Test Template
    template_json:
      zabbix_export:
        version: '3.2'
        templates:
          - name: Template for Testing
            description: 'Testing template import'
            template: Test Template
            groups:
              - name: Templates
            applications:
              - name: Test Application
    template_groups: Templates
    state: present

# Add a macro to a template
- name: Set a macro on the Zabbix template
  local_action:
    module: zabbix_template
    server_url: http://127.0.0.1
    login_user: username
    login_password: password
    template_name: Template
    macros:
      - macro: '{$TEST_MACRO}'
        value: 'Example'
    state: present

# Remove a template
- name: Delete Zabbix template
  local_action:
    module: zabbix_template
    server_url: http://127.0.0.1
    login_user: username
    login_password: password
    template_name: Template
    state: absent

# Export template json definition
- name: Dump Zabbix template
  local_action:
    module: zabbix_template
    server_url: http://127.0.0.1
    login_user: username
    login_password: password
    template_name: Template
    state: dump
  register: template_dump

Return Values

Common return values are documented here, the following are the fields unique to this module:

Key Returned Description
template_json
string
when state is dump
The JSON dump of the template

Sample:
{'zabbix_export': {'date': '2017-11-29T16:37:24Z', 'templates': [{'templates': [], 'description': '', 'httptests': [], 'screens': [], 'applications': [], 'discovery_rules': [], 'groups': [{'name': 'Templates'}], 'name': 'Test Template', 'items': [], 'macros': [], 'template': 'test'}], 'version': '3.2', 'groups': [{'name': 'Templates'}]}}


Status

Authors

  • @sookido
  • Logan Vig (@logan2211)

Hint

If you notice any issues in this documentation you can edit this document to improve it.