community.zabbix.zabbix_host_info 模块 – 收集关于 Zabbix 主机的信息

注意

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

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

要安装它,请使用: ansible-galaxy collection install community.zabbix。您需要其他要求才能使用此模块,请参阅 要求 了解详细信息。

要在剧本中使用它,请指定: community.zabbix.zabbix_host_info

概要

  • 此模块允许您搜索 Zabbix 主机条目。

  • 在 Ansible 2.9 之前,此模块名为 zabbix_host_facts。用法没有改变。

要求

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

  • python >= 3.9

参数

参数

注释

exact_match

布尔值

查找完全匹配

选择

  • false ← (默认)

  • true

host_inventory

列表 / 元素=字符串

要在结果中显示的主机清单键列表。

如果未指定键,则检索整个主机清单。

默认值: []

host_ip

列表 / 元素=字符串

Zabbix 中主机的主机接口 IP。

当不使用 host_name 时是必需的。

默认值: []

host_name

字符串

Zabbix 中主机的名称。

host_name 是使用的唯一标识符,不能使用此模块更新。

当不使用 host_ip 时是必需的。

如果既未指定 host_name 也未指定 host_ip,则返回 Zabbix 中配置的所有主机。

默认值: ""

http_login_password

字符串

基本身份验证密码

http_login_user

字符串

基本身份验证登录名

remove_duplicate

布尔值

从主机结果中删除重复的主机

选择

  • false

  • 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: Get host info
  # 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_host_info:
    host_name: ExampleHost
    host_ip: 127.0.0.1
    exact_match: no
    remove_duplicate: yes

- name: Reduce host inventory information to provided keys
  # 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_host_info:
    host_name: ExampleHost
    host_inventory:
      - os
      - tag
    host_ip: 127.0.0.1
    exact_match: no
    remove_duplicate: yes

返回值

常见返回值记录在这里,以下是此模块独有的字段

描述

hosts

字典

Zabbix 主机列表。有关主机值列表,请参阅 https://www.zabbix.com/documentation/4.0/manual/api/reference/host/get

已返回: 成功

示例: [{"...": null, "available": "1", "description": "", "disable_until": "0", "error": "", "flags": "0", "groups": ["1"], "host": "Host A"}]

作者

  • Michael Miko (@RedWhiteMiko)