community.zabbix.zabbix_maintenance 模块 – 创建 Zabbix 维护窗口
注意
此模块是 community.zabbix 集合 (版本 3.2.0) 的一部分。
如果您使用的是 ansible 包,则可能已安装此集合。它不包含在 ansible-core 中。要检查它是否已安装,请运行 ansible-galaxy collection list。
要安装它,请使用: ansible-galaxy collection install community.zabbix。您需要其他要求才能使用此模块,有关详细信息,请参阅 要求。
要在 playbook 中使用它,请指定: community.zabbix.zabbix_maintenance。
概要
- 此模块允许您创建 Zabbix 维护窗口。 
要求
执行此模块的主机需要以下要求。
- python >= 3.9 
参数
| 参数 | 注释 | 
|---|---|
| 维护生效的时间。 给定的值将向下舍入到分钟。 如果未指定,则使用 `datetime.datetime.now()`。 默认值:  | |
| 维护失效的时间。 给定的值将向下舍入到分钟。 如果未指定,则根据 *minutes* 计算。 默认值:  | |
| 维护类型。是否收集数据。 选项 
 | |
| 维护窗口的简短描述。 默认值:  | |
| 要为其管理维护窗口的主机组。 当 *state=present* 且 *host_names* 未使用时,为必需选项。 | |
| 要为其管理维护窗口的主机。 当 *state=present* 且 *host_groups* 未使用时,为必需选项。 | |
| 基本身份验证密码 | |
| 基本身份验证用户名 | |
| 维护窗口的长度(分钟)。 默认值:  | |
| 维护窗口的唯一名称。 | |
| 创建或删除维护窗口。要删除的维护窗口由名称标识。 选项 
 | |
| 要分配给维护中主机的标签列表。 需要 *collect_data=yes*。 | |
| 条件运算符。 可能的值是 0 - 等于 2 - 包含 默认值:  | |
| 标签的名称。 | |
| 标签的值。 默认值:  | |
| 用于识别要包含在维护中的主机的 Zabbix 主机名称类型。 *visible_name=yes* 表示按显示名称搜索,*visible_name=no* 表示按技术名称搜索。 选项 
 | 
备注
注意
- 对于在大型更新之前将主机设置为维护模式并在更新后删除维护窗口很有用。 
- 模块从 now() 到 now() + minutes 创建维护窗口,因此如果 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
- name: Create a named maintenance window for host www1 for 90 minutes
  # 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_maintenance:
    name: Update of www1
    host_name: www1.example.com
    state: present
    minutes: 90
- name: Create a named maintenance window for host www1 and host groups Office and Dev
  # 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_maintenance:
    name: Update of www1
    host_name: www1.example.com
    host_groups:
      - Office
      - Dev
    state: present
    tags:
      - tag: ExampleHostsTag
      - tag: ExampleHostsTag2
        value: ExampleTagValue
      - tag: ExampleHostsTag3
        value: ExampleTagValue
        operator: 0
- name: Create a named maintenance window for hosts www1 and db1, without data collection.
  # 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_maintenance:
    name: update
    host_names:
      - www1.example.com
      - db1.example.com
    state: present
    collect_data: false
- name: Remove maintenance window by name
  # 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_maintenance:
    name: Test1
    state: absent
- name: Create maintenance window by date
  # 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_maintenance:
    name: TestDate
    state: present
    host_names:
      - host.example.org
    active_since: "1979-09-19 09:00"
    active_till: "1979-09-19 17:00"
