community.vmware.vmware_host_facts module – Gathers facts about remote ESXi hostsystem
Note
This module is part of the community.vmware collection (version 1.18.2).
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
hostname
andesxi_hostname
is not specified, then the module will throw an error.VSAN facts added in 2.7 version.
SYSTEM fact uuid added in 2.10 version.
Please note that when ESXi host connection state is not
connected
, facts returned from vCenter might be stale.
Requirements
The below requirements are needed on the host that executes this module.
python >= 2.6
PyVmomi
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 Environment variable support added in Ansible 2.6. |
|
The password of the vSphere vCenter or ESXi server. If the value is not specified in the task, the value of environment variable Environment variable support added in Ansible 2.6. |
|
The port number of the vSphere vCenter or ESXi server. If the value is not specified in the task, the value of environment variable Environment variable support added in Ansible 2.6. Default: 443 |
|
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:
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 This feature depends on a version of pyvmomi greater than v6.7.1.2018.12 |
|
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 ‘summary’ output schema is the legacy output from the module The ‘vsphere’ output schema is the vSphere API class definition which requires pyvmomi>6.7.1 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 Environment variable support added in Ansible 2.6. |
|
Allows connection when SSL certificates are not valid. Set to If the value is not specified in the task, the value of environment variable Environment variable support added in Ansible 2.6. If set to Choices:
|
Notes
Note
All modules requires API write access and hence is not supported on a free ESXi license.
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 }}"
Authors
Wei Gao (@woshihaoren)