Ansible on VMware ESXi 8 Automation Complete Guide
By Luca Berton · Published 2024-01-01 · Category: installation
Automate VMware vSphere 8 / ESXi 8 with Ansible: community.vmware and vmware.vmware_rest collections, vCenter, VMs, networking, storage, NSX.
VMware vSphere 8 (ESXi 8.0 U3) is the current VMware platform under Broadcom stewardship. Ansible automates ESXi hosts and vCenter through two complementary collections: community.vmware (mature, pyVmomi-based) and vmware.vmware_rest (REST-based, generated from vSphere REST API). General Support runs through October 2027 and Technical Guidance to October 2029. This is the master Ansible guide for vSphere 8.
vSphere 8 release facts
| Item | Value | |---|---| | ESXi build | 8.0 Update 3 | | GA | 2022-10-11 | | General Support | until 2027-10-11 | | Technical Guidance | until 2029-10-11 | | Hypervisor APIs | vSphere REST API, SOAP (legacy) |
See also: List Tags in VMware Datastore Using Ansible
Ansible-core compatibility
Use ansible-core 2.18 LTS. Required Python libs:
pip install pyvmomi vsphere-automation-sdk-python aiohttp
Collections:
# requirements.yml
collections:
- name: community.vmware
version: ">=5.0.0"
- name: vmware.vmware_rest
version: ">=4.0.0"
Inventory (control-node delegated)
Most VMware tasks run from localhost against vCenter:
[vcenter]
vc01 ansible_connection=local
[vcenter:vars]
vcenter_hostname=vc01.lab.example.com
vcenter_username=administrator@vsphere.local
vcenter_password='{{ vault_vc_password }}'
vcenter_validate_certs=false
See also: Ansible VMware Dynamic Inventory: Complete Guide (2026)
Add an ESXi host to vCenter
- name: Add ESXi 8 to vCenter
hosts: localhost
gather_facts: false
tasks:
- name: Add host
community.vmware.vmware_host:
hostname: "{{ vcenter_hostname }}"
username: "{{ vcenter_username }}"
password: "{{ vcenter_password }}"
datacenter_name: DC01
cluster_name: Cluster01
esxi_hostname: esxi-01.lab.example.com
esxi_username: root
esxi_password: "{{ vault_esxi_password }}"
state: present
validate_certs: false
Provision a VM
- name: Deploy VM from content library
hosts: localhost
gather_facts: false
tasks:
- name: Deploy from OVA template
vmware.vmware_rest.vcenter_vmtemplate_libraryitems:
vcenter_hostname: "{{ vcenter_hostname }}"
vcenter_username: "{{ vcenter_username }}"
vcenter_password: "{{ vcenter_password }}"
vcenter_validate_certs: false
name: app-01
library_item_id: "{{ ubuntu24_template_id }}"
placement:
cluster: "{{ cluster_id }}"
folder: "{{ folder_id }}"
resource_pool: "{{ rp_id }}"
state: present
register: new_vm
- name: Power on
vmware.vmware_rest.vcenter_vm_power:
vcenter_hostname: "{{ vcenter_hostname }}"
vcenter_username: "{{ vcenter_username }}"
vcenter_password: "{{ vcenter_password }}"
vcenter_validate_certs: false
state: start
vm: "{{ new_vm.value.vm_id | default(new_vm.value) }}"
See also: Configuring Ansible for VMware: Complete Setup Guide & Playbook
Manage standard portgroups
- name: Add portgroup to vSwitch
hosts: localhost
gather_facts: false
tasks:
- name: Add VM portgroup
community.vmware.vmware_portgroup:
hostname: "{{ vcenter_hostname }}"
username: "{{ vcenter_username }}"
password: "{{ vcenter_password }}"
validate_certs: false
switch_name: vSwitch0
portgroup_name: VLAN-100
vlan_id: 100
esxi_hostname: esxi-01.lab.example.com
state: present
Datastore management
- name: Mount NFS datastore
hosts: localhost
gather_facts: false
tasks:
- name: NFS datastore
community.vmware.vmware_host_datastore:
hostname: "{{ vcenter_hostname }}"
username: "{{ vcenter_username }}"
password: "{{ vcenter_password }}"
validate_certs: false
esxi_hostname: esxi-01.lab.example.com
datastore_name: nfs-shared
datastore_type: nfs
nfs_server: nfs.lab.example.com
nfs_path: /vol/vmware
state: present
Maintenance mode + patching
- name: Enter maintenance mode and patch
hosts: localhost
gather_facts: false
tasks:
- name: Maintenance mode
community.vmware.vmware_maintenancemode:
hostname: "{{ vcenter_hostname }}"
username: "{{ vcenter_username }}"
password: "{{ vcenter_password }}"
validate_certs: false
esxi_hostname: esxi-01.lab.example.com
state: present
- name: Apply baseline (vLCM)
community.vmware.vmware_host_lockdown: # placeholder; vLCM modules per environment
hostname: "{{ vcenter_hostname }}"
username: "{{ vcenter_username }}"
password: "{{ vcenter_password }}"
validate_certs: false
esxi_hostname: esxi-01.lab.example.com
state: present
Best practices
• Prefervmware.vmware_rest for new playbooks — it tracks the supported REST API.
• Use community.vmware when you need pyVmomi-only features (older API surfaces).
• Always set validate_certs: false only in lab; use proper PKI in production.
• Drive vLCM (Lifecycle Manager) baselines from Ansible roles, not GUI.
Conclusion
vSphere 8 + Ansible delivers full VM and host lifecycle management. Combine community.vmware and vmware.vmware_rest collections, gate runs through change windows, and integrate with AAP for governed VMware operations.
Category: installation