Ansible-galaxy throws ImportError: No module named yaml

28.6k Views Asked by At


When I try to install ansible role, I see this exception.

 $ ansible-galaxy install zzet.postgresql
 Traceback (most recent call last):
 File "/Users/myHomeDir/.homebrew/Cellar/ansible/1.4.3/libexec/bin/ansible-galaxy", line 34, in <module>
 import yaml
 ImportError: No module named yaml

OS: Mac Os Maverick
Ansible: 1.4.3

Does anyone know how to fix it?

5

There are 5 best solutions below

2
On BEST ANSWER

Based on the error message, it tries to import the python module yaml but cannot find it. The yaml module is called pyyaml when you install it with pip:

pip install pyyaml

If pip is not installed on your mac then you can install it as,

easy_install pip

1
On

I tried the pip install yaml answer, and it didn't work for me. I had to reinstall ansible in order for the command line to catch. IE,

failing

ansible-galaxy install bcen01.nodejs                          [43m] ✭
Traceback (most recent call last):
  File "/usr/local/Cellar/ansible/1.4.3/libexec/bin/ansible-galaxy", line 34, in <module>
    import yaml
ImportError: No module named yaml

reinstall

brew reinstall ansible

success

ansible-galaxy install bcen01.nodejs                          [43m] ✭
 no version specified, installing master
 - downloading role from https://github.com/bcen/ansible-nodejs/archive/master.tar.gz
 - extracting bcen01.nodejs to /usr/local/etc/ansible/roles/bcen01.nodejs
bcen01.nodejs was installed successfully
0
On

Run below commands to install latest yaml-

wget http://pyyaml.org/download/pyyaml/PyYAML-3.12.tar.gz

tar -xvzf PyYAML-3.12.tar.gz

cd PyYAML-3.12

python setup.py install

Python 2.7.12 (default, Sep 21 2017, 21:46:26)
[GCC 4.8.4] on linux2
Type "help", "copyright", "credits" or "license" for more information.

    >>> import yaml
    >>>
0
On

For me pip install yaml doesn’t work in Mavericks.

pip install pyyaml works

0
On

Try installing with

sudo python -m easy_install pyyaml

The problem isn't in pyyaml, its in your version of setuptools. See http://codyaray.com/2011/12/pyyaml-using-easy_install-on-mac-os-x-lion for references