msg: httplib2 is not installed for uri module when httplib2 is installed

Running the task

  • name: Get tenant id
    uri: url=“{{ os_service_endpoint }}/tenants?name={{tenant.name}}”
    method=GET
    timeout=30
    return_content=yes
    HEADER_User-Agent=python-keystoneclient
    HEADER_X-Auth-Token=“{{keystone_admin_token}}”
    HEADER_Content-Type=“application/json”
    register: register_tenant

TASK: [Get tenant id] *********************************************************

REMOTE_MODULE uri url=“http://example.com:35357/v2.0//tenants?name=tenant2” method=GET timeout=30 return_content=yes HEADER_User-Agent=python-keystoneclient HEADER_X-Auth-Token=“*****” HEADER_Content-Type=“application/json”

EXEC [‘/bin/sh’, ‘-c’, ‘mkdir -p $HOME/.ansible/tmp/ansible-tmp-1398201502.91-131706600599036 && echo $HOME/.ansible/tmp/ansible-tmp-1398201502.91-131706600599036’]

PUT /var/folders/t2/h22337c12hn279xwd4s9fk7s8_088c/T/tmpLEIdmk TO /Users/kbroughton/.ansible/tmp/ansible-tmp-1398201502.91-131706600599036/uri

EXEC /bin/sh -c ‘sudo -k && sudo -H -S -p “[sudo via ansible, key=turelpokuakqdltyqvhjhfyyvmrqaail] password: " -u root /bin/sh -c '”’“‘echo SUDO-SUCCESS-turelpokuakqdltyqvhjhfyyvmrqaail; /usr/bin/python /Users/kbroughton/.ansible/tmp/ansible-tmp-1398201502.91-131706600599036/uri; rm -rf /Users/kbroughton/.ansible/tmp/ansible-tmp-1398201502.91-131706600599036/ >/dev/null 2>&1’”‘"’’

failed: [localhost] => {“failed”: true, “item”: “”}

msg: httplib2 is not installed

FATAL: all hosts have already failed – aborting

Do you have ‘localhost’ defined in your inventory? If so, have you specified ansible_python_interpreter=/usr/local/bin/python along with it in your inventory?

You do mention that /usr/bin/python has access to httplib2, but that could be due to something such as setting PYTHONPATH somewhere that would allow /usr/bin/python to load httplib2 that it wouldn’t otherwise have access to, and as a result ansible is running without access to PYTHONPATH maybe…

The code that determines if you have httplib2 is somewhat simple:

HAS_HTTPLIB2 = True
try:
import httplib2
except ImportError:
HAS_HTTPLIB2 = False

And later if HAS_HTTPLIB2 is False, it fails with the message you are seeing.

Perhaps try running:

/usr/bin/python -c “import httplib2; print httplib2.file
/usr/local/bin/python -c “import httplib2; print httplib2.file

As well as looking at:

echo $PYTHONPATH

httplib2 is getting picked up from the same place for either python install.

[kbroughton@mb-kbroughton:Contents/MacOS] /usr/bin/python -c “import httplib2; print httplib2.file

/usr/local/lib/python2.7/site-packages/httplib2/init.pyc

[kbroughton@mb-kbroughton:Contents/MacOS] /usr/local/bin/python -c “import httplib2; print httplib2.file

/usr/local/lib/python2.7/site-packages/httplib2/init.pyc

PYTHONPATH is pointing there

[kbroughton@mb-kbroughton:Contents/MacOS] echo $PYTHONPATH

/usr/local/lib/python2.7/site-packages:/Users/kbroughton/vcp/git/mentat/ansible/lib:

But i’m not sure how to force pip to install it to the location that ansible has access to.

[kbroughton@mb-kbroughton:Contents/MacOS] export PYTHONPATH=‘’

[kbroughton@mb-kbroughton:Contents/MacOS] echo $PYTHONPATH

[kbroughton@mb-kbroughton:Contents/MacOS] pip install httplib2

Requirement already satisfied (use --upgrade to upgrade): httplib2 in /usr/local/lib/python2.7/site-packages

Cleaning up…

[kbroughton@mb-kbroughton:Contents/MacOS]

I suppose that pip belongs to the homebrew installed python, and i don’t have pip installed for /usr/bin/python.

Setting ansible_python_interpreter=/usr/local/bin/python in the hosts file fixes the problem.

kesten

I’ve often found that using python from homebrew causes more problems than it solves.

You can probably do something like:

sudo PYTHONPATH=“” /usr/bin/easy_install httplib2

On Mac, usually one of the first things I do is:

sudo /usr/bin/easy_install pip

Unfortunately that will try to squash pip provided by homebrew installed python as they both use /usr/local/bin/pip as their destination.

If you want to use python from homebrew, then your inventory modification is probably the right change to make.

Either that , or don’t target localhost explicitly, remove localhost from your inventory and use local_action or delegate_to: localhost, which does some magic (implicit localhost) and uses the python binary used to invoke ansible as ansible_python_interpreter.