community.vmware.vmware_host_facts 模块 – 收集远程 ESXi 主机系统的信息
注意
此模块是 community.vmware 集合(版本 5.2.0)的一部分。
如果您正在使用 ansible 包,则可能已经安装了此集合。它不包含在 ansible-core 中。要检查是否已安装,请运行 ansible-galaxy collection list。
要安装它,请使用: ansible-galaxy collection install community.vmware。
要在剧本中使用它,请指定: community.vmware.vmware_host_facts。
概要
- 此模块可用于收集有关 ESXi 主机系统的 CPU、内存、数据存储、网络和系统等信息。 
- 请将 ESXi 主机系统的主机名或 IP 地址指定为 - hostname。
- 如果将 vCenter 的主机名或 IP 地址作为 - hostname提供,并且未指定- esxi_hostname,则该模块将抛出错误。
- 请注意,当 ESXi 主机连接状态不是 - connected时,从 vCenter 返回的事实可能已过时。建议用户检查连接状态值并在剧本中做出适当的决策。
参数
| 参数 | 注释 | 
|---|---|
| ESXi 主机名。 将返回有关指定 ESXi 服务器的主机信息。 通过指定此选项,您可以选择在连接到 vCenter 时返回哪个 ESXi 主机系统。 | |
| vSphere vCenter 或 ESXi 服务器的主机名或 IP 地址。 如果未在任务中指定该值,则将使用环境变量  | |
| vSphere vCenter 或 ESXi 服务器的密码。 如果未在任务中指定该值,则将使用环境变量  | |
| 指定要检索的属性。 如果未指定,则会检索所有属性(深度)。 结果将以与 vsphere API 相同的结构返回。 示例 properties: [ “hardware.memorySize”, “hardware.cpuInfo.numCpuCores”, “config.product.apiVersion”, “overallStatus” ] 仅当  | |
| 将接收所有 HTTPS 请求并中继它们的 HTTP 代理的端口。 如果任务中未指定该值,则将使用环境变量  | |
| 指定所需的输出模式。 
 
 选项 
 | |
| 如果设置为  选项 
 | |
| 如果设置为  选项 
 | |
| vSphere vCenter 或 ESXi 服务器的用户名。 如果任务中未指定该值,则将使用环境变量  | |
| 当 SSL 证书无效时允许连接。当证书不可信任时设置为  如果任务中未指定该值,则将使用环境变量  选项 
 | 
说明
注意
- 所有模块都需要 API 写入权限,因此不支持免费的 ESXi 许可证。 
- 所有变量和 VMware 对象名称都区分大小写。 
示例
- name: Gather vmware host facts
  community.vmware.vmware_host_facts:
    hostname: "{{ esxi_server }}"
    username: "{{ esxi_username }}"
    password: "{{ esxi_password }}"
  register: host_facts
  delegate_to: localhost
- name: Gather vmware host facts from vCenter
  community.vmware.vmware_host_facts:
    hostname: "{{ vcenter_hostname }}"
    username: "{{ vcenter_username }}"
    password: "{{ vcenter_password }}"
    esxi_hostname: "{{ esxi_hostname }}"
  register: host_facts
  delegate_to: localhost
- name: Gather vmware host facts from vCenter with tag information
  community.vmware.vmware_host_facts:
    hostname: "{{ vcenter_hostname }}"
    username: "{{ vcenter_username }}"
    password: "{{ vcenter_password }}"
    esxi_hostname: "{{ esxi_hostname }}"
    show_tag: true
  register: host_facts_tag
  delegate_to: localhost
- name: Get VSAN Cluster UUID from host facts
  community.vmware.vmware_host_facts:
    hostname: "{{ esxi_server }}"
    username: "{{ esxi_username }}"
    password: "{{ esxi_password }}"
  register: host_facts
- set_fact:
    cluster_uuid: "{{ host_facts['ansible_facts']['vsan_cluster_uuid'] }}"
- name: Gather some info from a host using the vSphere API output schema
  community.vmware.vmware_host_facts:
    hostname: "{{ vcenter_hostname }}"
    username: "{{ vcenter_username }}"
    password: "{{ vcenter_password }}"
    esxi_hostname: "{{ esxi_hostname }}"
    schema: vsphere
    properties:
      - hardware.memorySize
      - hardware.cpuInfo.numCpuCores
      - config.product.apiVersion
      - overallStatus
  register: host_facts
- name: Gather information about powerstate and connection state
  community.vmware.vmware_host_facts:
    hostname: "{{ vcenter_hostname }}"
    username: "{{ vcenter_username }}"
    password: "{{ vcenter_password }}"
    esxi_hostname: "{{ esxi_hostname }}"
    schema: vsphere
    properties:
      - runtime.connectionState
      - runtime.powerState
- name: How to retrieve Product, Version, Build, Update info for ESXi from vCenter
  block:
    - name: Gather product version info for ESXi from vCenter
      community.vmware.vmware_host_facts:
        hostname: "{{ vcenter_hostname }}"
        username: "{{ vcenter_username }}"
        password: "{{ vcenter_password }}"
        esxi_hostname: "{{ esxi_hostname }}"
        schema: vsphere
        properties:
          - config.product
          - config.option
      register: gather_host_facts_result
    - name: Extract update level info from option properties
      set_fact:
        update_level_info: "{{ item.value }}"
      loop: "{{ gather_host_facts_result.ansible_facts.config.option }}"
      when:
        - item.key == 'Misc.HostAgentUpdateLevel'
    - name: The output of Product, Version, Build, Update info for ESXi
      debug:
        msg:
          - "Product : {{ gather_host_facts_result.ansible_facts.config.product.name }}"
          - "Version : {{ gather_host_facts_result.ansible_facts.config.product.version }}"
          - "Build   : {{ gather_host_facts_result.ansible_facts.config.product.build }}"
          - "Update  : {{ update_level_info }}"
