ansible.builtin.zabbix_template (v2.8.13) — module

Create/delete/dump Zabbix template

| "added in version" 2.5 of ansible.builtin"

Authors: sookido (@sookido), Logan Vig (@logan2211)

preview | supported by community

Install Ansible via pip

Install with pip install ansible==2.8.13

Description

Create/delete/dump Zabbix template.


Requirements

Usage examples

  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
---
# 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
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# 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
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# 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
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# 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
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# 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
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# 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

Inputs

    
state:
    choices:
    - present
    - absent
    - dump
    default: present
    description:
    - 'State: present - create/update template; absent - delete template'
    required: false

macros:
    description:
    - List of template macros.
    required: false

template_json:
    description:
    - JSON dump of template to import.
    required: false

template_name:
    description:
    - Name of Zabbix template.
    - Required when I(template_json) is not used.
    required: false

link_templates:
    description:
    - List of templates linked to the template.
    required: false

clear_templates:
    description:
    - List of templates cleared from the template.
    - See templates_clear in https://www.zabbix.com/documentation/3.0/manual/api/reference/template/update
    required: false

http_login_user:
    description:
    - Basic Auth login
    required: false
    type: str

template_groups:
    description:
    - List of template groups to create or delete.
    - Required when I(template_name) is used and C(state=present).
    required: false

http_login_password:
    description:
    - Basic Auth password
    required: false
    type: str

Outputs

template_json:
  description: The JSON dump of the template
  returned: when state is dump
  sample:
    zabbix_export:
      date: '2017-11-29T16:37:24Z'
      groups:
      - name: Templates
      templates:
      - applications: []
        description: ''
        discovery_rules: []
        groups:
        - name: Templates
        httptests: []
        items: []
        macros: []
        name: Test Template
        screens: []
        template: test
        templates: []
      version: '3.2'
  type: str