How to use pip modules when you install Ansible with brew
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:
Wait.. didn’t I just install that?
pip show pyvmomi
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
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:
And sure enough, my playbook started to correctly resolve my previously installed Ansible module.