community.zabbix.zabbix_templategroup 模块 – 创建/删除 Zabbix 模板组

注意

此模块是 community.zabbix 集合(版本 3.2.0)的一部分。

如果您使用的是 ansible 包,您可能已经安装了此集合。它不包含在 ansible-core 中。要检查是否已安装,请运行 ansible-galaxy collection list

要安装它,请使用:ansible-galaxy collection install community.zabbix。您需要进一步的要求才能使用此模块,请参阅 要求 了解详情。

要在 playbook 中使用它,请指定:community.zabbix.zabbix_templategroup

概要

  • 如果模板组不存在则创建它们。

  • 如果模板组存在则删除它们。

要求

在执行此模块的主机上需要以下要求。

  • python >= 2.6

参数

参数

注释

http_login_password

字符串

基本身份验证密码

http_login_user

字符串

基本身份验证登录名

状态

字符串

创建或删除模板组。

选项

  • "present" ← (默认)

  • "absent"

template_groups

别名: template_group

列表 / 元素=字符串 / 必需

要创建或删除的模板组列表。

注释

注意

  • 对同一组的并发更新过多可能会导致 Zabbix 返回错误,如果需要,请参阅示例中的解决方法。

示例

# 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

# Base create template groups example
- name: Create template groups
  # 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_templategroup:
    state: present
    template_groups:
      - Example group1
      - Example group2

# Limit the Zabbix group creations to one template since Zabbix can return an error when doing concurrent updates
- name: Create template groups
  # 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_templategroup:
    state: present
    template_groups:
      - Example group1
      - Example group2
  when: inventory_hostname==groups['group_name'][0]

作者

  • Cove (@cove)

  • Tony Minfei Ding

  • Harrison Gu (@harrisongu)