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

**URL:** <https://forum.ansible.com/t/dynamic-inventory-script-doesnt-run-under-ansible-but-a-script-that-cats-its-output-works-just-fine/18763>\
**Category:** Ansible Project\
**Created:** [July 15, 2015, 3:39am UTC](https://forum.ansible.com/t/dynamic-inventory-script-doesnt-run-under-ansible-but-a-script-that-cats-its-output-works-just-fine/18763 "2015-07-15T03:39:59Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![pixel\_fairy](https://avatars.discourse-cdn.com/v4/letter/p/6f9a4e/32.png) [@pixel\_fairy](https://forum.ansible.com/u/pixel_fairy)\
**Post date:** [July 15, 2015, 3:39am UTC](https://forum.ansible.com/t/dynamic-inventory-script-doesnt-run-under-ansible-but-a-script-that-cats-its-output-works-just-fine/18763/1 "2015-07-15T03:39:59Z")

</div>

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,

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [July 15, 2015, 3:47am UTC](https://forum.ansible.com/t/dynamic-inventory-script-doesnt-run-under-ansible-but-a-script-that-cats-its-output-works-just-fine/18763/2 "2015-07-15T03:47:50Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![pixel\_fairy](https://avatars.discourse-cdn.com/v4/letter/p/6f9a4e/32.png) [@pixel\_fairy](https://forum.ansible.com/u/pixel_fairy)\
**Post date:** [July 15, 2015, 2:14pm UTC](https://forum.ansible.com/t/dynamic-inventory-script-doesnt-run-under-ansible-but-a-script-that-cats-its-output-works-just-fine/18763/3 "2015-07-15T14:14:08Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [July 15, 2015, 5:35pm UTC](https://forum.ansible.com/t/dynamic-inventory-script-doesnt-run-under-ansible-but-a-script-that-cats-its-output-works-just-fine/18763/4 "2015-07-15T17:35:34Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![pixel\_fairy](https://avatars.discourse-cdn.com/v4/letter/p/6f9a4e/32.png) [@pixel\_fairy](https://forum.ansible.com/u/pixel_fairy)\
**Post date:** [July 15, 2015, 9:09pm UTC](https://forum.ansible.com/t/dynamic-inventory-script-doesnt-run-under-ansible-but-a-script-that-cats-its-output-works-just-fine/18763/5 "2015-07-15T21:09:55Z")

</div>

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” “$@”

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [July 15, 2015, 9:14pm UTC](https://forum.ansible.com/t/dynamic-inventory-script-doesnt-run-under-ansible-but-a-script-that-cats-its-output-works-just-fine/18763/6 "2015-07-15T21:14:30Z")

</div>

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