4

I installed ansible, apache-libcloud with pip. Also, I can use the gcloud cli and ansible works for any non-gce-related playbooks.

When using the gce module as a task to create instances in an ansible playbook, the following error occurs:

TASK: [Launch instances] ****************************************************** 
<127.0.0.1> REMOTE_MODULE gce instance_names=mm2 machine_type=f1-micro image=ubuntu-1204-precise-v20150625 zone=europe-west1-d service_account_email= pem_file=../pkey.pem project_id=fancystuff-11
<127.0.0.1> EXEC ['/bin/sh', '-c', 'mkdir -p $HOME/.ansible/tmp/ansible-tmp-1437669562.03-233461447935889 && chmod a+rx $HOME/.ansible/tmp/ansible-tmp-1437669562.03-233461447935889 && echo $HOME/.ansible/tmp/ansible-tmp-1437669562.03-233461447935889']
<127.0.0.1> PUT /var/folders/v4/ll0_f8lj7yl7yghb645h95q9ckfc19/T/tmpyDoPt9 TO /Users/d046179/.ansible/tmp/ansible-tmp-1437669562.03-233461447935889/gce
<127.0.0.1> EXEC ['/bin/sh', '-c', u'LANG=en_US.UTF-8 LC_CTYPE=en_US.UTF-8 /usr/bin/python /Users/d046179/.ansible/tmp/ansible-tmp-1437669562.03-233461447935889/gce; rm -rf /Users/d046179/.ansible/tmp/ansible-tmp-1437669562.03-233461447935889/ >/dev/null 2>&1']
failed: [localhost -> 127.0.0.1] => {"failed": true, "parsed": false}
failed=True msg='libcloud with GCE support (0.13.3+) required for this module'


FATAL: all hosts have already failed -- aborting

And the site.yml of the playbook I wrote:

 name: Create a sandbox instance
  hosts: localhost
  vars:
    names: mm2
    machine_type: f1-micro
    image: ubuntu-1204-precise-v20150625
    zone: europe-west1-d
    service_account_email: xxx@developer.gserviceaccount.com
    pem_file: ../pkey.pem
    project_id: fancystuff-11
  tasks:
    - name: Launch instances
      local_action: gce instance_names={{names}} machine_type={{machine_type}}
                    image={{image}} zone={{zone}} service_account_email={{ service_account_email }}
                    pem_file={{ pem_file }} project_id={{ project_id }}
      register: gce

The gce cloud module fails with the error message "ibcloud with GCE support (0.13.3+) required for this module". However, running gce.py from the ansible github repo works. The python script finds the apache-libcloud library and prints a json with all running instances. Besides, pip install apache-libcloud states it is installed properly.

Is there anything I am missing like an environment variable that points to the python libraries (PYTHONPATH)?


UPDATE 1:

I included the following task before the gce task:

- name: install libcloud
  pip: name=apache-libcloud

This also does not affect the behavior nor prevents any error messages.


Update 2:

I added the following task to inspect the available PYTHONPATH:

- name: Getting PYTHONPATH
  local_action: shell python -c 'import sys; print(":".join(sys.path))'
  register: pythonpath
- debug:  
    msg: "PYTHONPATH: {{ pythonpath.stdout }}"

The following is returned:

PYTHONPATH: :/usr/local/lib/python2.7/site-packages/setuptools-17.1.1-py2.7.egg:/usr/local/lib/python2.7/site-packages/pip-7.0.3-py2.7.egg:/usr/local/lib/python2.7/site-packages:/usr/local/Cellar/python/2.7.10/Frameworks/Python.framework/Versions/2.7/lib/python27.zip:/usr/local/Cellar/python/2.7.10/Frameworks/Python.framework/Versions/2.7/lib/python2.7:/usr/local/Cellar/python/2.7.10/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin:/usr/local/Cellar/python/2.7.10/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac:/usr/local/Cellar/python/2.7.10/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages:/usr/local/Cellar/python/2.7.10/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk:/usr/local/Cellar/python/2.7.10/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old:/usr/local/Cellar/python/2.7.10/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload:/usr/local/lib/python2.7/site-packages:/Library/Python/2.7/site-packages

UPDATE 3:

I introduced my own test.py script as a task which executes the same apache-libcloud imports as the gce ansible module. The script imports just fine!!!

user1595955
  • 71
  • 1
  • 4
  • 1
    I'm seeing that mac homebrew does a per-python project site-packages. Ansible has it's own site-packages folder at /usr/local/Cellar/ansible/1.9.2/libexec/vendor/lib/python2.7/site-packages which must have the library. – xrl Aug 26 '15 at 22:38

5 Answers5

2

Setting the PYTHONPATH fixes the issue. For example:

$ export PYTHONPATH=/usr/local/lib/python2.7/site-packages/

mlazarov
  • 404
  • 3
  • 7
1

I'm using OSX and I solved this for myself. Short answer: install ansible with pip. (rather than e.g. brew)

I inspected the PYTHONPATH that Ansible sets runtime and it looked like it had nothing to do whith my normal system PYTHONPATH. E.g. for me, my system PYTHONPATH was empty, and setting that like e.g. mlazarov suggested didn't make any difference. I made ansible print the PYTHONPATH it uses runtime, and it looked like this:

ok: [localhost] => {
"msg": "PYTHONPATH: :/usr/local/Cellar/ansible/1.9.4/libexec/lib/python2.7/site-packages:/usr/local/Cellar/ansible/1.9.4/libexec/vendor/lib/python2.7/site-packages:/Library/Frameworks/Python.framework/Versions/3.4/lib/python34.zip:/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4:/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/plat-darwin:/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/lib-dynload:/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages"
}

So there's only ansible's own site-packages and some strange Python3 installations (I'm using python2.7)

Something in this discussion made me think it might be a problem with the ansible installation, my ansible was installed with brew. I reinstalled it globally with pip (simply running sudo pip install ansible), and that fixed the problem. Now the PYTHONPATH ansible prints looks much better, with my virtualenv python installation in the beginning, and no more "libcloud with GCE support (0.13.3+) required for this module".

lilline
  • 133
  • 8
0

I was able to resolve the issue by setting the PYTHONPATH environment variable (export PYTHONPATH=/path/to/site-packages) with the current site-packages folder. Apparently, ansible establishes its own environment during module execution and ignores any paths available in python except the paths from the environment variable PYTHONPATH.

I find this a peculiar behavior which is not documented on the ansible websites.

user1595955
  • 71
  • 1
  • 4
  • the site-packages (or dist-packages) should be in your path by default. I wonder if something has clobbered environment settings somewhere along the way. – cgseller Jul 30 '15 at 19:34
0

I have a similar environment setup. I found some information at the bottom of this section: https://github.com/jlund/streisand#prerequisites

Essentially there's some magic files you can update so the brew'd ansible will add a folder to search for packages:

mkdir -p ~/Library/Python/2.7/lib/python/site-packages
echo '/usr/local/lib/python2.7/site-packages' > ~/Library/Python/2.7/lib/python/site-packages/homebrew.pth

Hope that fixes it for you!

xrl
  • 2,155
  • 5
  • 26
  • 40
0

In my case it was the case of:

pip install apache-libcloud
Carlos Henrique Cano
  • 1,458
  • 11
  • 15