Although Ansible is typically used to execute tasks on multiple machines concurrently by generating Python scripts from YAML files and copying over those scripts to the remote machines for execution, it can also be used to execute tasks for remote endpoints on the local machine by executing the “Python-from-YAML” scripts locally. This use-case is typical for remote endpoints which do not have a Python execution environment (e.g. Network devices, VMware hosts and vCenter).
Since Ansible and all modules shipped with it are written in Python, we need a Python API/SDK to call VMware’s vSphere API to perform tasks on ESXi hosts and vCenter. This Python SDK is pyVmomi.
Execute the following commands on a RHEL/CentOS machine (with connectivity to the internet) to setup an environment to use Ansible for VMware:
# Install ansible sudo yum install ansible # Install the pip python package manager sudo yum install python2-pip.noarch # Upgrade pip sudo pip install --upgrade pip # Install pyVmomi sudo pip install pyvmomi