How to configure a Python Virtual Environment for Ansible VMware?
Using a Python Virtual Environment is a convenient way to maintain up-to-date the Python dependency of the Ansible collection community.vmware without interfere with your Linux system/
This initial configuration sometimes is a roadblock for some VMware users to start using Ansible.
I'm Luca Berton and welcome in today's episode of Ansible Pilot.
Links
- [Ansible collection community.vmware](https://docs.ansible.com/ansible/latest/collections/community/vmware/index.html)
- [Python pyVmomi](https://github.com/vmware/pyvmomi)
- [VMware vSphere Automation SDK for Python](https://github.com/vmware/vsphere-automation-sdk-python)
Playbook
Configure a Python Virtual Environment for Ansible VMware:
- pyVmomi
- requests
- VMware vSphere Automation SDK for Python
How to Python Virtual Environment for Ansible VMware.
I'm going to show you how to configure a Python Virtual Environment for Ansible VMware to successfully use the Ansible collection community.vmware of modules and plugins to manages various operations related to virtual machines in the given ESXi or vCenter server.
Ansible VMware modules are written on top of pyVmomi Python SDK for the VMware vSphere API that allows user to manage ESX, ESXi, and vCenter infrastructure.
Other useful libraries are requests and VMware vSphere Automation SDK for Python used for some additional features such as list tags in the Ansible Dynamic Inventory vmware_vm_inventory plugin.
code
``bash
$ python3.8 -m venv venv
$ source venv/bin/activate
(venv) $ pip3.8 install --upgrade pip
(venv) $ pip3.8 install requests
(venv) $ pip3.8 install pyvmomi
(venv) $ pip3.8 install --upgrade git+https://github.com/vmware/vsphere-automation-sdk-python.git
`
execution
``bash
[devops@demo ~]$ python3.8 -m venv venv
[devops@demo ~]$ source venv/bin/activate
(venv) [devops@demo ~]$ pip install -U pip
Collecting pip
Using cached https://files.pythonhosted.org/packages/96/2f/caec18213f6a67852f6997fb0673ae08d2e93d1b81573edb93ba4ef06970/pip-22.1.2-py3-none-any.whl
Installing collected packages: pip
Found existing installation: pip 19.3.1
Uninstalling pip-19.3.1:
Successfully uninstalled pip-19.3.1
Successfully installed pip-22.1.2
(venv) [devops@demo ~]$ pip install requests
Collecting requests
Using cached requests-2.28.0-py3-none-any.whl (62 kB)
Collecting idna<4,>=2.5
Using cached idna-3.3-py3-none-any.whl (61 kB)
Collect