24


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?

sorin
  • 161,544
  • 178
  • 535
  • 806
Alexander Vagin
  • 575
  • 1
  • 8
  • 15

5 Answers5

45

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

Gaurav Gandhi
  • 3,041
  • 2
  • 27
  • 40
Vilsepi
  • 1,347
  • 14
  • 18
13

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

pip install pyyaml works

Joe
  • 1,312
  • 20
  • 24
1

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
the Tin Man
  • 158,662
  • 42
  • 215
  • 303
westonplatter
  • 1,475
  • 2
  • 19
  • 30
1

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

0

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
    >>>
Abhishek Kulkarni
  • 3,693
  • 8
  • 35
  • 42