community.zabbix.zabbix_globalmacro 模块 – 创建/更新/删除 Zabbix 全局宏
注意
此模块是 community.zabbix 集合 (版本 3.2.0) 的一部分。
如果您使用的是 ansible 包,则可能已安装此集合。它不包含在 ansible-core 中。要检查是否已安装,请运行 ansible-galaxy collection list。
要安装它,请使用:ansible-galaxy collection install community.zabbix。您需要其他要求才能使用此模块,有关详细信息,请参阅 要求。
要在剧本中使用它,请指定:community.zabbix.zabbix_globalmacro。
community.zabbix 1.4.0 中的新增功能
概要
- 管理 Zabbix 全局宏,可以创建、更新或删除它们。 
- 对于 macro_type Secret,由于文本的机密性,无法验证 value 字段,并且该字段将始终被覆盖。 
要求
执行此模块的主机需要以下要求。
- python >= 3.9 
参数
| 参数 | 注释 | 
|---|---|
| 仅当设置为  选项 
 | |
| 基本身份验证密码 | |
| 基本身份验证用户名 | |
| 全局宏的文本描述。 默认值:  | |
| Zabbix 原生格式  | |
| 全局宏类型:文本或秘密文本。 如果 state=present,则需要。 text secret - 秘密文本 仅适用于 Zabbix >= 5.0,在较低版本中将默认为 Text vault - Vault 秘密 仅适用于 Zabbix >= 5.2,在较低版本中将默认为 Text 选项 
 | |
| 全局宏的值。 如果 state=present,则需要。 | |
| 宏的状态。 在  在  选项 
 | 
备注
注意
- 当 macro_type=secret 时,此模块返回 changed=true。 
示例
# 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
- name: Create new global macro or update an existing macro's value
  # 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_globalmacro:
    macro_name: EXAMPLE.MACRO
    macro_value: Example value
    macro_type: 0
    macro_description: Example description
    state: present
# Values with curly brackets need to be quoted otherwise they will be interpreted as a dictionary
- name: Create new global macro in Zabbix native format with Secret Type
  # 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_globalmacro:
    macro_name: "{$EXAMPLE.MACRO}"
    macro_value: Example value
    macro_type: 1
    macro_description: Example description
    state: present
- name: Delete existing global macro
  community.zabbix.zabbix_globalmacro:
    macro_name: "{$EXAMPLE.MACRO}"
    state: absent
