Christoffer Reijer
Christoffer Reijer

Reputation: 1995

Ansible cannot find pyVmomi

I recently upgraded to OSX High Sierra and now I get this whenever I try to use vmware_guest in Ansible on my Mac:

fatal: [localhost -> localhost]: FAILED! => {"changed": false, "msg": "PyVmomi 
Python module required. Install using \"pip install PyVmomi\""}

As you can see it doesn't find pyVmomi. Note that this is delegated to localhost, so it is running on my Mac, not on some remote server. I have tried to install and reinstall pyVmomi, and even reinstalled my whole python installation. As you can see, the module is there:

➜  environment git:(rhel) python -c "from pyVmomi import vim"
➜  environment git:(rhel) python2 -c "from pyVmomi import vim"
➜  environment git:(rhel) python3 -c "from pyVmomi import vim"

I am using:

Upvotes: 3

Views: 6909

Answers (4)

Rafael Ganascim
Rafael Ganascim

Reputation: 1

I had the same issue. To solve it, I uninstalled pyvim and PyVmomi, and installed only PyVmomi.

Upvotes: 0

mxb
mxb

Reputation: 1

I had the same issue with High Sierra 10.13.6. My python2.7 installation is via brew. My ansible was NOT installed via pip.

So I run 'pip install ansible'. After that pyVmomi got found and it's working.

Upvotes: 0

Jim Littlefield
Jim Littlefield

Reputation: 26

After much digging i found the problem on my machine to be a different package missing. This code from ansible/vmware.py was the culprit:

   try:
    # requests is required for exception handling of the ConnectionError
    import requests
    from pyVim import connect
    from pyVmomi import vim, vmodl
    HAS_PYVMOMI = True
except ImportError:
    HAS_PYVMOMI = False

`

You have to be able to import all of the imports in this try block to set HAS_PYVMOMI to True On my machine I was missing a package that was being imported by requests and therefore the try block was failing. uninstalling and reinstalling pyVmomi did not help and would not help. My machine is a CentOS 7.4 VM.

Upvotes: 1

Nobody
Nobody

Reputation: 3

I had exactly the same issue using the python:2 docker image on Ubuntu.

You likely have an inventory file that defines localhost. Remove localhost from your inventory file, or change the location of your 'inventory' parameter in your ansible.cfg.

For completeness, although I don't think this is what OP wants: Alternatively, you might try supplying credentials for your local machine, or use 'delegate_to: some-other-host' which has pyvmomi installed to run the tasks for you.

Upvotes: 0

Related Questions