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

**URL:** <https://forum.ansible.com/t/msg-httplib2-is-not-installed-for-uri-module-when-httplib2-is-installed/15068>\
**Category:** Ansible Project\
**Created:** [April 22, 2014, 9:43pm UTC](https://forum.ansible.com/t/msg-httplib2-is-not-installed-for-uri-module-when-httplib2-is-installed/15068 "2014-04-22T21:43:36Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kesten\_Broughton2](https://avatars.discourse-cdn.com/v4/letter/k/ecc23a/32.png) [@Kesten\_Broughton2](https://forum.ansible.com/u/Kesten_Broughton2)\
**Post date:** [April 22, 2014, 9:43pm UTC](https://forum.ansible.com/t/msg-httplib2-is-not-installed-for-uri-module-when-httplib2-is-installed/15068/1 "2014-04-22T21:43:36Z")

</div>

Running the task

- name: Get tenant id  
uri: url=“{{ os\_service\_endpoint }}/tenants?name={{[tenant.name](http://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](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

---

<div class="post-metadata">

**Author:** ![sivel](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sivel/32/1198_2.png) [@sivel](https://forum.ansible.com/u/sivel)\
**Post date:** [April 22, 2014, 9:59pm UTC](https://forum.ansible.com/t/msg-httplib2-is-not-installed-for-uri-module-when-httplib2-is-installed/15068/2 "2014-04-22T21:59:23Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Kesten\_Broughton2](https://avatars.discourse-cdn.com/v4/letter/k/ecc23a/32.png) [@Kesten\_Broughton2](https://forum.ansible.com/u/Kesten_Broughton2)\
**Post date:** [April 23, 2014, 1:33pm UTC](https://forum.ansible.com/t/msg-httplib2-is-not-installed-for-uri-module-when-httplib2-is-installed/15068/3 "2014-04-23T13:33:20Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![sivel](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sivel/32/1198_2.png) [@sivel](https://forum.ansible.com/u/sivel)\
**Post date:** [April 23, 2014, 5:07pm UTC](https://forum.ansible.com/t/msg-httplib2-is-not-installed-for-uri-module-when-httplib2-is-installed/15068/4 "2014-04-23T17:07:54Z")

</div>

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.
