AnsiblePilot — Master Ansible Automation
AnsiblePilot is the leading resource for learning Ansible automation, DevOps, and infrastructure as code. Browse over 1,100 tutorials covering Ansible modules, playbooks, roles, collections, and real-world examples. Whether you are a beginner or an experienced engineer, our step-by-step guides help you automate Linux, Windows, cloud, containers, and network infrastructure.
Popular Topics
About Luca Berton
Luca Berton is an Ansible automation expert, author of "Ansible for VMware by Examples" and "Ansible for Kubernetes by Example" published by Apress, and creator of the Ansible Pilot YouTube channel. He shares practical automation knowledge through tutorials, books, and video courses to help IT professionals and DevOps engineers master infrastructure automation.
Configuring Ansible for VMware: Complete Setup Guide & Playbook — Video Tutorial
Learn how to set up Ansible for VMware with pyVmomi and the community.vmware collection. Follow our guide to configure and run your first VMware playbook.
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
Full Tutorial Content
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 6.0, 5.5, 5.1 and 5.0
- Python pyVmomi supports 2.7.x and 3.4+
- Ansible collection `community.vmware`
The supported nodes include all the modern releases of VMware vSphere.
The full list includes vSphere 6.0, 5.5, 5.1, and 5.0.
Ansible VMware modules are written on top of pyVmomi. pyVmomi is the Python SDK for the VMware vSphere API that allows users to manage ESX, ESXi, and vCenter infrastructure.
This library interacts with the VMware vSphere API that allows you to manage ESX, ESXi, and vCenter in order to execute some Ansible code.
The `pyVmomi` Python library supports Python 2.7.x and 3.4+.
The Ansible collection `community.vmware` of modules and plugins manages various operations related to virtual machines in the given ESXi or vCenter server.
As the name suggests, this resource is provided with only Community Support so it's not maintained directly by the Ansible Engineer Team.
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] ********************************************************************************
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: ModuleNotFoundError: No module named 'pyVim'
fatal: [localhost]: FAILED! => {"ansible_facts": {"discovered_interpreter_python": "/usr/libexec/platform-python"}, "changed": false, "msg": "Failed to import the required Python library (PyVmomi) on demo.example.com's Python /usr/libexec
About This Tutorial
- Author: Luca Berton
- Difficulty: Beginner
- Read time: 5 min
- Category: installation
Read the full written article: Configuring Ansible for VMware: Complete Setup Guide & Playbook