community.vmware.vmware_host_facts module – Gathers facts about remote ESXi hostsystem
Note
This module is part of the community.vmware collection (version 4.7.1).
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. - 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 string | 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. |
hostname string | 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 |
password aliases: pass, pwd string | The password of the vSphere vCenter or ESXi server. If the value is not specified in the task, the value of environment variable |
port integer | 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: |
properties list / elements=string | 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 |
proxy_host string | 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 |
proxy_port integer | 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 |
schema string | Specify the output schema desired. The The Choices:
|
show_datacenter boolean added in community.vmware 4.2.0 | Return the related Datacenter if set to Choices:
|
show_tag boolean | Tags related to Host are shown if set to Choices:
|
username aliases: admin, user string | The username of the vSphere vCenter or ESXi server. If the value is not specified in the task, the value of environment variable |
validate_certs boolean | 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 }}"
Collection links
© 2012–2018 Michael DeHaan
© 2018–2024 Red Hat, Inc.
Licensed under the GNU General Public License version 3.
https://docs.ansible.com/ansible/latest/collections/community/vmware/vmware_host_facts_module.html