dynamic inventory script doesnt run under ansible, but a script that cats its output works just fine.

wrote a dynamic inventory for ansible, which seems to run fine on its own, but when run in ansible, it complains that it cant import yaml.

a script that just cats out the output (cut and paste) of the first script works just fine. the parts that actually make and configure the virtual machines and networks works fine, so thats stripped out.

im on os x 10.10.4, running ansible 1.9.2 from homebrew

pixel$ ./pransible-stripped.py --list
{
“fileserver”: {

pixel$ ansible -i ./pransible-stripped.py all --list-hosts
ERROR: Inventory script (./pransible-stripped.py) had an execution error: Traceback (most recent call last):
File “/Users/pixel/pransible-stripped.py”, line 4, in
import yaml
File “/usr/local/Cellar/ansible/1.9.2/libexec/vendor/lib/python2.7/site-packages/yaml/init.py”, line 2, in
from error import *
ImportError: No module named ‘error’

pixel$ cat pransible-stripped.sh
#!/bin/sh
cat<<EOF
{
“fileserver”: {

pixel$ ansible -i ./pransible-stripped.sh all --list-hosts
erp
rndweb
rndrouter
fileserver

heres the script,

so ansible uses python2 which would require yaml to work and seems to
be installed correctly, but your script uses python3, did you install
yaml for python 3?

Yes, the rest the script (stripped out for brevity) works fine. checked for all needed packages in both versions of python, but ansible insists on its own (python2) version of yaml. is there a way around that? like telling ansible not to use its own yaml?

ill probably just generate a static inventory file, but that seems silly when the only issue a different version of the same language.

ansible is not responsible for the yaml version in this case, that
depens on your script, ansible just executes invenory scripts, it does
not even know if it is python, ruby or C, just that it is executable.

are you setting PYTHONPATH for ansible? in that case the env variable
would get inherited by the subprocess.

turns out homebrew set that python path. running from git works as it should.

pixel$ cat which ansible
#!/bin/bash
PYTHONPATH=“/usr/local/Cellar/ansible/1.9.2/libexec/lib/python2.7/site-packages:/usr/local/Cellar/ansible/1.9.2/libexec/vendor/lib/python2.7/site-packages” exec “/usr/local/Cellar/ansible/1.9.2/libexec/bin/ansible” “$@”

This is one reason we removed homebrew from our instructions on how to
install ansible.