The title of this post is a bit misleading, because the TLDR is, “don’t!”. Instead, install Ansible using pip and all the path troubles will resolve themselves.

A bit more detail:

I decided to give the vmware management module pyvmomi a whirl so I could run VMWare API commands using Ansible after I realized that the Terraform provider for vsphere is still pretty immature.

So the first step to get this working is to install the module, like so:

pip install pyvmomi

But, when I ran my playbook, I saw this disconcerting output:

pyvmomi is required for this module

Wait.. didn’t I just install that?

pip show pyvmomi

Name: pyvmomi
Version: 6.7.0
Summary: VMware vSphere Python SDK
Home-page: https://github.com/vmware/pyvmomi
Author: VMware, Inc.
Author-email: jhu@vmware.com
License: License :: OSI Approved :: Apache Software License
Location: /usr/local/lib/python2.7/site-packages
Requires: requests, six
Required-by:

Yeah.. so what’s the deal?

So then I thrashed around a bit, trying to be more explicity about where my Ansible module library was stored.

ansible-playbook -i austin vmware.yml --module-path "./library/pyvmomi/"

and also:

ANSIBLE_LIBRARY="/usr/local/lib/python2.7/site-packages/" ansible-playbook -i austin vmware.yml --ask-pass

All to no avail. Then I decided to take a closer look at my Ansible install, and I remembered that I had installed Ansible using Brew.. could this be affecting my ability to see pip modules?

ansible --version

ansible (master) $ ansible-playbook --version
ansible-playbook 2.4.3.0
  config file = /Users/jharding/config-wizard/ansible/ansible.cfg
  configured module search path = [u'/Users/jharding/config-wizard/ansible/"/usr/local/lib/python2.7/site-packages/"']
  ansible python module location = /usr/local/Cellar/ansible/2.4.3.0/libexec/lib/python2.7/site-packages/ansible
  executable location = /usr/local/bin/ansible-playbook
  python version = 2.7.10 (default, Oct  6 2017, 22:29:07) [GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.31)]

Ah ha! Look at that “ansible python module location”.. definitely not somewhere pip knew about.

So in order to keep my file system clean of one-off symlinks or module duplication, I simply ran:

brew uninstall ansible

followed by

pip install ansible

Then I verified my path looked a bit more sane:

ansible 2.6.0
  config file = None
  configured module search path = [u'/Users/jharding/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/lib/python2.7/site-packages/ansible
  executable location = /usr/local/bin/ansible
  python version = 2.7.15 (default, May  1 2018, 16:44:08) [GCC 4.2.1 Compatible Apple LLVM 9.1.0 (clang-902.0.39.1)]

And sure enough, my playbook started to correctly resolve my previously installed Ansible module.