community.vmware.vmware_host_facts module – Gathers facts about remote ESXi hostsystem
Note
This module is part of the community.vmware collection (version 5.9.0).
You might already have this collection installed if you are using the ansible package.
It is not included in ansible-core.
To check whether it is installed, run ansible-galaxy collection list.
To install it, use: ansible-galaxy collection install community.vmware.
To use it in a playbook, specify: community.vmware.vmware_host_facts.
Synopsis
- This module can be used to gathers facts like CPU, memory, datastore, network and system etc. about ESXi host system. 
- Please specify hostname or IP address of ESXi host system as - hostname.
- If hostname or IP address of vCenter is provided as - hostnameand- esxi_hostnameis not specified, then the module will throw an error.
- Please note that when ESXi host connection state is not - connected, facts returned from vCenter might be stale. Users are recommended to check connection state value and take appropriate decision in the playbook.
Parameters
| Parameter | Comments | 
|---|---|
| ESXi hostname. Host facts about the specified ESXi server will be returned. By specifying this option, you can select which ESXi hostsystem is returned if connecting to a vCenter. | |
| The hostname or IP address of the vSphere vCenter or ESXi server. If the value is not specified in the task, the value of environment variable  | |
| The password of the vSphere vCenter or ESXi server. If the value is not specified in the task, the value of environment variable  | |
| The port number of the vSphere vCenter or ESXi server. If the value is not specified in the task, the value of environment variable  Default:  | |
| Specify the properties to retrieve. If not specified, all properties are retrieved (deeply). Results are returned in a structure identical to the vsphere API. Example: properties: [ “hardware.memorySize”, “hardware.cpuInfo.numCpuCores”, “config.product.apiVersion”, “overallStatus” ] Only valid when  | |
| Address of a proxy that will receive all HTTPS requests and relay them. The format is a hostname or a IP. If the value is not specified in the task, the value of environment variable  | |
| Port of the HTTP proxy that will receive all HTTPS requests and relay them. If the value is not specified in the task, the value of environment variable  | |
| Specify the output schema desired. The  The  Choices: 
 | |
| Return the related Datacenter if set to  Choices: 
 | |
| Tags related to Host are shown if set to  Choices: 
 | |
| The username of the vSphere vCenter or ESXi server. If the value is not specified in the task, the value of environment variable  | |
| Allows connection when SSL certificates are not valid. Set to  If the value is not specified in the task, the value of environment variable  Choices: 
 | 
Notes
Note
- All modules requires API write access and hence is not supported on a free ESXi license. 
- All variables and VMware object names are case sensitive. 
Examples
- 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 }}"
