community.vmware.vmware_host_facts – Gathers facts about remote ESXi hostsystem¶
Note
This plugin is part of the community.vmware collection (version 1.9.0).
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.
Requirements¶
The below requirements are needed on the host that executes this module.
python >= 2.6
PyVmomi
Parameters¶
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)