ansible can't find pycurl on OSX

2019-02-27 20:57发布

问题:

I'm just getting started with ansible, and I'm trying to get it to work with the linode module from OSX Yosemite. I'm using brew-installed Python, and pip-installed ansible. So I have done the following:

$ brew install python
$ PYCURL_SSL_LIBRARY=nss pip install pycurl
$ CFLAGS=-Qunused-arguments CPPFLAGS=-Qunused-arguments pip install ansible

To test:

$ which python
/usr/local/bin/python

$ python --version
Python 2.7.9

$ which ansible
/usr/local/bin/ansible

$ ansible --version
ansible 1.8.2
   configured module search path = None

When I run my playbook I get:

failed=True msg='pycurl required for this module'

So somehow ansible is not seeing the pycurl library.

Here is the playbook:

---
- hosts: 127.0.0.1
  connection: local
  gather_facts: no

  tasks:
  - name: "provision a server"
    local_action:
      module: linode
      api_key: FOO
      name: linode-test1
      plan: 1
      datacenter: 1
      distribution: 99
      password: 'superSecureRootPassword'
      ssh_pub_key: ssh-rsa FOO
      swap: 768
      wait: yes
      wait_timeout: 600
      state: present

回答1:

It's happening on ubuntu as well, finally figured out the solution. You need to explicity pass path to python executable

Change Ansible hosts file from

[local]
localhost

to

[local]
localhost ansible_python_interpreter=/usr/local/bin/python

or to your virtual environment python path.



回答2:

I was able to fix this on OS X El Capitan 10.11.6 by editing hosts:

[local]
localhost ansible_python_interpreter=/usr/local/bin/python

You may then need additional Python dependencies:

pip install pycurl
pip install linode-python