# ansible-playbook using -i inventory on a playbook fails on pyVmomi not found

**URL:** <https://forum.ansible.com/t/ansible-playbook-using-i-inventory-on-a-playbook-fails-on-pyvmomi-not-found/27704>\
**Category:** Ansible Project\
**Created:** [June 4, 2018, 8:20pm UTC](https://forum.ansible.com/t/ansible-playbook-using-i-inventory-on-a-playbook-fails-on-pyvmomi-not-found/27704 "2018-06-04T20:20:23Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![Wendell\_MacKenzie](https://avatars.discourse-cdn.com/v4/letter/w/c77e96/32.png) [@Wendell\_MacKenzie](https://forum.ansible.com/u/Wendell_MacKenzie)\
**Post date:** [June 4, 2018, 8:20pm UTC](https://forum.ansible.com/t/ansible-playbook-using-i-inventory-on-a-playbook-fails-on-pyvmomi-not-found/27704/1 "2018-06-04T20:20:23Z")

</div>

Hi:

I have a playbook that uses vmware\_guest module to create a new VM on an esxi server. The inventory specified on the command line  
does not have localhost defined. I _DO_ specify delegate\_to: localhost in the task definition where vmware\_guest is used. It fails with the  
error message :

module pyVmomi not found

presumably as this module is not found on the esxi server where vmware\_guest is being run. pyVmomi _IS_ installed on localhost as reported  
by pip show pyVmomi.

ideas??

thx.  
Wendell

---

<div class="post-metadata">

**Author:** ![Varun\_Chopra](https://avatars.discourse-cdn.com/v4/letter/v/54ee81/32.png) [@Varun\_Chopra](https://forum.ansible.com/u/Varun_Chopra)\
**Post date:** [June 5, 2018, 7:48am UTC](https://forum.ansible.com/t/ansible-playbook-using-i-inventory-on-a-playbook-fails-on-pyvmomi-not-found/27704/2 "2018-06-05T07:48:36Z")

</div>

You’re not delegating properly.

---

<div class="post-metadata">

**Author:** ![Alexsey\_S](https://avatars.discourse-cdn.com/v4/letter/a/f6c823/32.png) [@Alexsey\_S](https://forum.ansible.com/u/Alexsey_S)\
**Post date:** [June 5, 2018, 4:31pm UTC](https://forum.ansible.com/t/ansible-playbook-using-i-inventory-on-a-playbook-fails-on-pyvmomi-not-found/27704/3 "2018-06-05T16:31:41Z")

</div>

pyVmomi has to be installed on the host you running ansible.

and also make sure pyVmomi is installed for correct version of python used by ansible v2 vs v3, if you have multiple versions installed

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [June 5, 2018, 6:28pm UTC](https://forum.ansible.com/t/ansible-playbook-using-i-inventory-on-a-playbook-fails-on-pyvmomi-not-found/27704/4 "2018-06-05T18:28:39Z")

</div>

running ansible with -v will show you the python used locally, which  
applies to localhost if you have not defined it in inventory, if so,  
its up to you to define ansible\_python\_interpreter.

[http://docs.ansible.com/ansible/latest/inventory/implicit\_localhost.html?highlight=implicit](http://docs.ansible.com/ansible/latest/inventory/implicit_localhost.html?highlight=implicit)

---

<div class="post-metadata">

**Author:** ![Wendell\_MacKenzie](https://avatars.discourse-cdn.com/v4/letter/w/c77e96/32.png) [@Wendell\_MacKenzie](https://forum.ansible.com/u/Wendell_MacKenzie)\
**Post date:** [June 5, 2018, 8:05pm UTC](https://forum.ansible.com/t/ansible-playbook-using-i-inventory-on-a-playbook-fails-on-pyvmomi-not-found/27704/5 "2018-06-05T20:05:30Z")

</div>

So, after banging my head around this for 2 days, I gave up and went to the method of using virtualenvs instead.

Tried to install ansible and PyVmomi using pip and it complained about setuptools being out of date. When doing that  
upgrade it pooched the whole pip install. pip would not run after - generated an ImportError on sysconfig not found from get\_platform.  
Apparently a known issue with older (python 2.6) environments. So, looking like I’ll have to go to rhel 7 sooner than we wanted.

Note on the installation error that was initially reported, the problem I _believe_ was that ansible was not installed on our box that  
has internet connectivity so when PyVmomi was installed, it got put down into /usr/lib/python2.6/site-packages. However, on the  
target system where I was trying to run it from ansible, it was being searched for in /usr/lib/python2.6/site-packages/ansible/modules  
and module\_utils. So, I suspected you MUST install ansible before installing PyVmomi to get things properly configured in the  
python realm.

thx.  
Wendell

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [June 5, 2018, 8:16pm UTC](https://forum.ansible.com/t/ansible-playbook-using-i-inventory-on-a-playbook-fails-on-pyvmomi-not-found/27704/6 "2018-06-05T20:16:54Z")

</div>

No, order of installation should not matter, as long as all libraries  
are in python's search path during execution.

---

<div class="post-metadata">

**Author:** ![Wendell\_MacKenzie](https://avatars.discourse-cdn.com/v4/letter/w/c77e96/32.png) [@Wendell\_MacKenzie](https://forum.ansible.com/u/Wendell_MacKenzie)\
**Post date:** [June 5, 2018, 8:22pm UTC](https://forum.ansible.com/t/ansible-playbook-using-i-inventory-on-a-playbook-fails-on-pyvmomi-not-found/27704/7 "2018-06-05T20:22:23Z")

</div>

Well, all I can say is when the ansible task kicked off trying to invoke vmware\_guest module, it failed reporting that the  
PyVmomi package was not found.

I used strace -f to follow execution of where python was looking for it and it was looking in:

/usr/lib/python2.6/site-packages/ansible/modules and module\_utils.

why, I have no clue. the library setting in the ansible setup was default and module location path was reported via -vvv as

/usr/lib/python2.6/site-packages/ansible.

Note that the actual files installed for the PyVmomi package went into:

/usr/lib/python2.6/site-packages

so I suspect that’s why it wasn’t found.

is this configurable somehow?

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [June 5, 2018, 8:25pm UTC](https://forum.ansible.com/t/ansible-playbook-using-i-inventory-on-a-playbook-fails-on-pyvmomi-not-found/27704/8 "2018-06-05T20:25:42Z")

</div>

if looking at the python exeucting ansible-playbook, that is expected,  
that is how ansible builds the module code it is going to ship and  
execute on the target.

You need to look at the fork invoked when executing the module itself  
(which uses it's own python) and does not expect module\_utils/modules  
but a zipped file (the one compiled in the step above) + the rest of  
the PYTHONPATH.

---

<div class="post-metadata">

**Author:** ![Wendell\_MacKenzie](https://avatars.discourse-cdn.com/v4/letter/w/c77e96/32.png) [@Wendell\_MacKenzie](https://forum.ansible.com/u/Wendell_MacKenzie)\
**Post date:** [June 5, 2018, 8:48pm UTC](https://forum.ansible.com/t/ansible-playbook-using-i-inventory-on-a-playbook-fails-on-pyvmomi-not-found/27704/9 "2018-06-05T20:48:19Z")

</div>

How does one look at the fork involved when executing the module itself to debug it?

The question I guess is how to tell that python instance to ALSO look at:

/usr/lib/python2.6/site-packages

too.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [June 5, 2018, 8:55pm UTC](https://forum.ansible.com/t/ansible-playbook-using-i-inventory-on-a-playbook-fails-on-pyvmomi-not-found/27704/10 "2018-06-05T20:55:56Z")

</div>

Using -vvv you should see exact python executed for the module, that  
should give you an idea of the pythonpath used.

ansible\_python\_interpreter controls the python used, in case you need  
to change it, but also if you really want to strace you can point at a  
wrapper script.

another option is using test-module utility in ansible repos  
'hacking/' directory

---

<div class="post-metadata">

**Author:** ![Wendell\_MacKenzie](https://avatars.discourse-cdn.com/v4/letter/w/c77e96/32.png) [@Wendell\_MacKenzie](https://forum.ansible.com/u/Wendell_MacKenzie)\
**Post date:** [June 5, 2018, 9:07pm UTC](https://forum.ansible.com/t/ansible-playbook-using-i-inventory-on-a-playbook-fails-on-pyvmomi-not-found/27704/11 "2018-06-05T21:07:20Z")

</div>

Ya, I’m using the -vvv setting which reports the interpreter being used and the module search path. The module search path just  
has /usr/lib/python2.6/site-packages/ansible in it. When explains the behaviour of why it is not finding PyVmomi. Can you just  
put a colon list of paths in the library variable in the ansible.cfg to have to like PATH work at the shell?

thx.  
Wendell

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [June 5, 2018, 9:13pm UTC](https://forum.ansible.com/t/ansible-playbook-using-i-inventory-on-a-playbook-fails-on-pyvmomi-not-found/27704/12 "2018-06-05T21:13:25Z")

</div>

No, as i said before, the module search path and the module execution  
are not directly related, the first is used by ansible to build the  
code package it will execute in the end.

The pyvimomi library is requried at execution, not at build time, so  
it must be installed so the python invoked at the target can find it.

---

<div class="post-metadata">

**Author:** ![Wendell\_MacKenzie](https://avatars.discourse-cdn.com/v4/letter/w/c77e96/32.png) [@Wendell\_MacKenzie](https://forum.ansible.com/u/Wendell_MacKenzie)\
**Post date:** [June 5, 2018, 9:44pm UTC](https://forum.ansible.com/t/ansible-playbook-using-i-inventory-on-a-playbook-fails-on-pyvmomi-not-found/27704/13 "2018-06-05T21:44:02Z")

</div>

The pyvmomi module is invoked and executes on the local Host. It uses their API to talk to esxi. I’ll play with the library ansible.cfg value tomorrow and see if I can adjust where it looks for modules.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [June 5, 2018, 11:28pm UTC](https://forum.ansible.com/t/ansible-playbook-using-i-inventory-on-a-playbook-fails-on-pyvmomi-not-found/27704/14 "2018-06-05T23:28:20Z")

</div>

pyvimomi is not an ansible module, its a python library some ansible  
modules use, ansible.cfg does handle module locations but NOT python  
library ones.

---

<div class="post-metadata">

**Author:** ![Wendell\_MacKenzie](https://avatars.discourse-cdn.com/v4/letter/w/c77e96/32.png) [@Wendell\_MacKenzie](https://forum.ansible.com/u/Wendell_MacKenzie)\
**Post date:** [June 6, 2018, 7:29pm UTC](https://forum.ansible.com/t/ansible-playbook-using-i-inventory-on-a-playbook-fails-on-pyvmomi-not-found/27704/15 "2018-06-06T19:29:27Z")

</div>

Ya, I figured that out. I downgraded the pyvmomi module to 5.5.0.2014.1.1 which supports python 2.6. Installed it  
and now I see it being attempted to be loaded. It’s failing on backports/ssl\_match\_hostname/re.py. For whatever  
reason, it is not using the established PYTHONPATH I set for this. I presume that somewhere in the call chain  
the core python path is being overridden. I guess it’s time to talk to the vmware guys…

---

<div class="post-metadata">

**Author:** ![tannerjc](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/tannerjc/32/985_2.png) [@tannerjc](https://forum.ansible.com/u/tannerjc)\
**Post date:** [June 7, 2018, 1:39pm UTC](https://forum.ansible.com/t/ansible-playbook-using-i-inventory-on-a-playbook-fails-on-pyvmomi-not-found/27704/16 "2018-06-07T13:39:40Z")

</div>

The 2014 package is way too old. You really should use the latest from pip.

---

<div class="post-metadata">

**Author:** ![Wendell\_MacKenzie](https://avatars.discourse-cdn.com/v4/letter/w/c77e96/32.png) [@Wendell\_MacKenzie](https://forum.ansible.com/u/Wendell_MacKenzie)\
**Post date:** [June 7, 2018, 7:30pm UTC](https://forum.ansible.com/t/ansible-playbook-using-i-inventory-on-a-playbook-fails-on-pyvmomi-not-found/27704/17 "2018-06-07T19:30:48Z")

</div>

Got it working late today. The issue with PyVmomi being reported as not being installed was due to dependencies on  
several python packages that were being imported in vmware.py but were not installed along with pyvmomi. These  
included:

- chardet
- certifi
- urllib3

I think that the above are dependencies on requests & six, not pyvmomi specifically. These packages were on the  
server being tested on and I assumed (incorrectly) that all the dependencies needed were also installed.

I then ran into cert issues when attempting to fire it up but got around that by upgrading to 6.0.0 which supports  
certs properly.

VM now being created. way cool 🙂

---

<div class="post-metadata">

**Author:** ![Wendell\_MacKenzie](https://avatars.discourse-cdn.com/v4/letter/w/c77e96/32.png) [@Wendell\_MacKenzie](https://forum.ansible.com/u/Wendell_MacKenzie)\
**Post date:** [June 7, 2018, 7:55pm UTC](https://forum.ansible.com/t/ansible-playbook-using-i-inventory-on-a-playbook-fails-on-pyvmomi-not-found/27704/18 "2018-06-07T19:55:59Z")

</div>

Figuring how this works under the hood took some hacking…but using the ansible var:

ANSIBLE\_KEEP\_REMOTE\_FILE=1

helped a lot. Then running the explode option to have it dump the vars json stuff into a file  
allowed the python child process to be debugged directly. this is how I figured out what the  
dependencies missing were.
