How to Gather Info about all VMware ESX/ESXi Hosts in a given Cluster with Ansible?
I’m going to show you a live Playbook and some simple Ansible code.
I’m Luca Berton and welcome to today’s episode of Ansible Pilot
Ansible Gather Info about all VMware ESX/ESXi Hosts in given Cluster
community.vmware.vmware_host_config_info
- Gathers info about an ESXi host’s advanced configuration information
Let’s talk about the Ansible module vmware_host_config_info.
The full name is community.vmware.vmware_host_config_info, which means that is part of the collection of modules to interact with VMware, community-supported.
The module's purpose is to gather info about an ESXi host’s advanced configuration information.
Parameters
hostnamestring / port integer / username string / password string / datacenter string / validate_certs boolean — connection details
cluster_namestring — Name of the cluster from which the ESXi host belongs to.
esxi_hostnamestring — ESXi hostname to gather information from.
The following parameters are useful in order to Gather Info about all VMware ESX/ESXi Hosts in the given Cluster using the module vmware_host_config_info.
First of all, we need to establish the connection with VMware vSphere or VMware vCenter using a plethora of self-explicative parameters: hostname, port, username, password, datacenter and validate_certs.
Once the connection is successfully established you could specify the full esxi_hostname, the ESX/ESXi hostname, or list all the hostnames in the current cluster cluster_name.
Links
- [
community.vmware.vmware_host_config_info](https://docs.ansible.com/ansible/latest/collections/community/vmware/vmware_cluster_info_module.html)
## Playbook
How to Gather Info about all VMware ESX/ESXi Hosts in given Cluster with Ansible.
I’m going to show you how to Gather Information on all the ESX/ESXi Host in the current VMware “production” cluster using Ansible Playbook.
code
- host_info_cluser.yml
``yaml
---
- name: host in cluster info Playbook
hosts: localhost
become: false
gather_facts: false
collections:
- community.vmware
pre_tasks:
- include_vars: vars.yml
tasks:
- name: Gather info about all ESXi Host in given Cluster
community.vmware.vmware_host_config_info:
hostname: '{{ vcenter_hostname }}'
username: '{{ vcenter_username }}'
password: '{{ vcenter_password }}'
validate_certs: "{{ vcenter_validate_certs }}"
cluster_name: "{{ cluster_name }}"
register: cluster_info
- name: print cluster info
ansible.builtin.debug:
var: cluster_info
`
- vars.yml
`yaml
---
vcenter_hostname: "vmware.example.com"
vcenter_datacenter: "vmwaredatacenter"
vcenter_validate_certs: false
vcenter_username: "[email protected]"
vcenter_password: "MySecretPassword123"
cluster_name: "production"
`
execution
``bash
$ ansible-playbook cluster_info.yml
PLAY [cluster