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.

Ansible troubleshooting - VMware Failed to Import PyVmomi — Video Tutorial

Let’s troubleshoot together the Ansible fatal error “Failed to import the required Python library (PyVmomi)” to find the root cause, install the required library using PIP, and successfully run our Ansible For VMware Playbook code.

Watch Video

Watch "Ansible troubleshooting - VMware Failed to Import PyVmomi" on YouTube

What You'll Learn

Full Tutorial Content

Ansible troubleshooting — VMware Failed to Import PyVmomi Today we’re going to talk about Ansible troubleshooting, specifically about the “Failed to import the required Python library (PyVmomi)” message and enable Ansible For VMware. This fatal error message happens when we are trying to execute some code against your VMware Infrastructure without the necessary Python SDK for the VMware vSphere API. These circumstances are usually related to the configuration of your Ansible Controller node and usually are not related to Ansible Playbook. I’m Luca Berton and welcome to today’s episode of Ansible Pilot. ## Playbook The best way of talking about Ansible troubleshooting is to jump in a live Playbook to show you practically the “Failed to import the required Python library (PyVmomi)” and how to solve it! In this Playbook, I’m going to reproduce the error and fix using the PIP, the Python Package Manager on a demo machine. error execution ```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/platform-python. Please read module documentation and install in the appropriate location. If the required library is installed, but Ansible is using the wrong Python interpreter, please consult the documentation on ansible_python_interpreter"} PLAY RECAP **************************************************************************************** localhost : ok=1 changed=0 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0 ``` fix code ```bash [devops@demo vmware]$ sudo su [root@demo vmware]# pip3 install PyVmomi WARNING: Running pip install with root privileges is generally not a good idea. Try `pip3 install --user` instead. Collecting PyVmomi Using cached https://files.pythonhosted.org/packages/d5/d1/effec9e03f9c0a0eba9c03ba8708807bad7b335341bf755cd88d110ce29d/pyvmomi-7.0.3.tar.gz Requirement already satisfied: requests>=2.3.0 in /usr/lib/python3.6/site-packages (from PyVmomi) Requirement already satisfied: six>=1.7.3 in /usr/lib/python3.6/site-packages (from PyVmomi) Requirement already satisfied: chardet<3.1.0,>=3.0.2 in /usr/lib/python3.6/site-packages (from requests>=2.3.0->PyVmomi) Requirement already satisfied: idna<2.8,>=2.5 in /usr/lib/python3.6/site-packages (from requests>=2.3.0->PyVmomi) Requirement already satisfied:

About This Tutorial

Read the full written article: Ansible troubleshooting - VMware Failed to Import PyVmomi

Topics Covered

Related Video Tutorials