What you'll learn
- How to configure Ansible for VMware?
- Configure Ansible for VMware
- Links
- missing Python PyVmomi library error
- Install PyVmomi
- Install community.vmware collection
- Ansible code
- Ansible execution
- Conclusion
- Related Articles
How to configure Ansible for VMware?
Ansible provides various modules to manage VMware infrastructure, which includes data center, cluster, host system, and virtual machine.
I'll show you step by step how to prepare your Ansible controller to interact with the VMware infrastructure.
This initial configuration sometimes is a roadblock for some VMware users to start using Ansible.
I'm Luca Berton and welcome to today's episode of Ansible Pilot.
Configure Ansible for VMware
- vSphere 8.0 and 7.0 (currently supported releases)
- Python 3.9+ with the `pyVmomi` SDK
- Ansible collection `community.vmware`
The `community.vmware` collection targets the vSphere releases that VMware (now Broadcom) still supports: vSphere 8.0 and 7.0. Earlier releases such as 6.7, 6.5, and the 5.x line have all reached end of general support, so plan an upgrade if you are still running them.
Ansible VMware modules are written on top of `pyVmomi`, the Python SDK for the VMware vSphere API that lets you manage ESXi and vCenter infrastructure.
This library talks to the vSphere API so your Ansible code can manage ESXi hosts, clusters, datacenters, and virtual machines.
Current `pyVmomi` releases require Python 3.x; the collection itself is tested against Python 3.9 and newer.
The `community.vmware` collection of modules and plugins manages a wide range of operations on the target ESXi or vCenter server.
As the name suggests, it is community-maintained rather than maintained directly by the core Ansible engineering team.
> **Note:** A REST-based alternative, the `vmware.vmware_rest` collection, talks to the vSphere REST API and does not need `pyVmomi`. For new automation, evaluate both: `community.vmware` has the widest module coverage, while `vmware.vmware_rest` avoids the `pyVmomi` dependency.
Links
- [Introduction to Ansible for VMware](https://docs.ansible.com/ansible/latest/collections/community/vmware/docsite/vmware_scenarios/vmware_intro.html)
- [community.vmware.vmware_guest_info](https://docs.ansible.com/ansible/latest/collections/community/vmware/vmware_guest_info_module.html)
## Playbook
How to configure Ansible for VMware:
1. Install pyVmomi
First of all, you need to install `pyVmomi` - the VMware vSphere API Python Bindings.
2. Install `community.vmware` collection
Second, you need to install the Ansible `community.vmware` collection.
3. Inventory & Playbook
Once everything is done on the node you could configure the Ansible inventory on the Ansible Controller machine and run your first Ansible Playbook with `vmware_guest_info` module to verify the successful configuration.
missing Python PyVmomi library error
```bash
$ ansible-playbook -i inventory vm_info.yml
PLAY [info vm Playbook] *******************************************************************************
TASK [include_vars] *******************************************************************************
ok: [localhost]
TASK [get VM info] ***************************************************