# Can't find boto for ansible EC2 module

**URL:** <https://forum.ansible.com/t/cant-find-boto-for-ansible-ec2-module/13247>\
**Category:** Ansible Project\
**Created:** [August 2, 2013, 2:52pm UTC](https://forum.ansible.com/t/cant-find-boto-for-ansible-ec2-module/13247 "2013-08-02T14:52:32Z")\
**Posts on this page:** 19\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dan\_McKean](https://avatars.discourse-cdn.com/v4/letter/d/ccd318/32.png) [@Dan\_McKean](https://forum.ansible.com/u/Dan_McKean)\
**Post date:** [August 2, 2013, 2:52pm UTC](https://forum.ansible.com/t/cant-find-boto-for-ansible-ec2-module/13247/1 "2013-08-02T14:52:32Z")

</div>

I’ve been considering Ansible for creating our EC2 instances, and have run into a problem with ansible not finding boto from either the command line or a playbook.

Here’s the command line and response; the playbook is similar:

ansible localhost -m ec2 -a “image=ami-0358ce33 instance\_type=t1.micro keypair=myKeypairName group=default wait=true”

localhost | FAILED \>\> {  
“failed”: true,  
“msg”: “boto required for this module”  
}

I’m running Ansible from an activated virtualenv. Ansible was installed with pip install ansible, and boto’s installed as well in the venv (as well as globally).

If I activate the venv and open a command prompt, I can import boto without any problem, and a boto.connect\_ec2() succeeds (there is a ~/.boto config file present). Importing ansible and creating a Runner works succeeds as well. I’m running this on Mac OS X.

Any suggestions on how to fix this? Thanks!

– Dan

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan](https://avatars.discourse-cdn.com/v4/letter/m/c4cdca/32.png) [@Michael\_DeHaan](https://forum.ansible.com/u/Michael_DeHaan)\
**Post date:** [August 2, 2013, 2:55pm UTC](https://forum.ansible.com/t/cant-find-boto-for-ansible-ec2-module/13247/2 "2013-08-02T14:55:13Z")

</div>

Ansible is not going to find boto in your virtualenv, so you need to install boto into site packages properly.

---

<div class="post-metadata">

**Author:** ![James\_Martin2](https://avatars.discourse-cdn.com/v4/letter/j/b9e5f3/32.png) [@James\_Martin2](https://forum.ansible.com/u/James_Martin2)\
**Post date:** [August 2, 2013, 3:16pm UTC](https://forum.ansible.com/t/cant-find-boto-for-ansible-ec2-module/13247/3 "2013-08-02T15:16:08Z")

</div>

In your hosts file, set your ansible\_python\_interpreter= the path of  
your python intepreter in your virtual env, it will work. For  
example:

[localhost]  
127.0.0.1 ansible\_python\_interpreter=/Users/jmartin/.virtualenvs/ansible-git/bin/python

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [August 2, 2013, 3:28pm UTC](https://forum.ansible.com/t/cant-find-boto-for-ansible-ec2-module/13247/4 "2013-08-02T15:28:12Z")

</div>

That too, but less to remember if you just install it like an app instead of realizing it’s a Python application and treating it special.

I use LOTS of apps without knowing what language they are written in.

---

<div class="post-metadata">

**Author:** ![Dan\_McKean](https://avatars.discourse-cdn.com/v4/letter/d/ccd318/32.png) [@Dan\_McKean](https://forum.ansible.com/u/Dan_McKean)\
**Post date:** [August 2, 2013, 4:27pm UTC](https://forum.ansible.com/t/cant-find-boto-for-ansible-ec2-module/13247/5 "2013-08-02T16:27:46Z")

</div>

Thanks, Michael!

boto is also install globally with pip and working fine.

What is the proper way to install boto for use by ansible on Mac OS X?

Dan

---

<div class="post-metadata">

**Author:** ![Dan\_McKean](https://avatars.discourse-cdn.com/v4/letter/d/ccd318/32.png) [@Dan\_McKean](https://forum.ansible.com/u/Dan_McKean)\
**Post date:** [August 2, 2013, 4:48pm UTC](https://forum.ansible.com/t/cant-find-boto-for-ansible-ec2-module/13247/6 "2013-08-02T16:48:55Z")

</div>

Thanks for your response.

As a practical matter for the environments and admin tools I develop, I can’t install Python applications and packages globally; they must be run in a virtual environment. That’s very common usage (our Django and Flask apps are virtualenv aware), and I’m a bit disappointed that I can’t just get Ansible up and running in a virtual environment… it’d be great if that were a bit more obvious in the docs, or there’s a blog post to point this simple usage out.

That being said, Ansible is a breath of fresh air… I’ve already been able to do quite a bit in just a few hours that would’ve taken me days with Chef and Puppet.

Thanks,

Dan

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [August 2, 2013, 5:32pm UTC](https://forum.ansible.com/t/cant-find-boto-for-ansible-ec2-module/13247/7 "2013-08-02T17:32:16Z")

</div>

Good to hear!

Yeah see James’s reply about ansible\_python\_interpreter.

It solves the problem too.

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [August 2, 2013, 5:32pm UTC](https://forum.ansible.com/t/cant-find-boto-for-ansible-ec2-module/13247/8 "2013-08-02T17:32:32Z")

</div>

I generally would do:

sudo pip install boto

---

<div class="post-metadata">

**Author:** ![Peter\_Sankauskas](https://avatars.discourse-cdn.com/v4/letter/p/ea666f/32.png) [@Peter\_Sankauskas](https://forum.ansible.com/u/Peter_Sankauskas)\
**Post date:** [August 2, 2013, 5:33pm UTC](https://forum.ansible.com/t/cant-find-boto-for-ansible-ec2-module/13247/9 "2013-08-02T17:33:50Z")

</div>

On OSX, there are many ways to use Python, and as you try to overwrite the default 2.6 that comes with OSX, things can get messy.

The best way I have found is using brew and pip. You will need to change your PATH so that brew’s install location is before the others, but essentially, it is:

$ brew install python  
$ pip install boto --upgrade

Peter Sankauskas

---

<div class="post-metadata">

**Author:** ![Chris\_Shenton](https://avatars.discourse-cdn.com/v4/letter/c/f9ae1b/32.png) [@Chris\_Shenton](https://forum.ansible.com/u/Chris_Shenton)\
**Post date:** [August 30, 2013, 5:07pm UTC](https://forum.ansible.com/t/cant-find-boto-for-ansible-ec2-module/13247/10 "2013-08-30T17:07:21Z")

</div>

Perfect, thanks for this.

---

<div class="post-metadata">

**Author:** ![Charles\_Mims](https://avatars.discourse-cdn.com/v4/letter/c/d2c977/32.png) [@Charles\_Mims](https://forum.ansible.com/u/Charles_Mims)\
**Post date:** [September 1, 2014, 2:46pm UTC](https://forum.ansible.com/t/cant-find-boto-for-ansible-ec2-module/13247/11 "2014-09-01T14:46:00Z")

</div>

FWIW, I have boto installed globally using pip:  
sudo pip install boto  
I can import boto into python without issue, but I get this same error message. I’m using OS X mavericks.

---

<div class="post-metadata">

**Author:** ![cosbug](https://avatars.discourse-cdn.com/v4/letter/c/13edae/32.png) [@cosbug](https://forum.ansible.com/u/cosbug)\
**Post date:** [April 14, 2015, 12:12pm UTC](https://forum.ansible.com/t/cant-find-boto-for-ansible-ec2-module/13247/12 "2015-04-14T12:12:49Z")

</div>

Hi,

I came across the same issue when I try to run cloudformation module in CentOS in python virtual env. (it used to work some time ago):  
(venv)[root@test ansible]# ansible-playbook aws-cf-provision.yml -vv  
…  
failed: [localhost] =\> {“failed”: true, “parsed”: false}  
failed=True msg=‘boto required for this module’  
Traceback (most recent call last):  
File “/root/.ansible/tmp/ansible-tmp-1429011194.43-47297413805384/cloudformation”, line 130, in   
sys.exit(1)  
NameError: name ‘sys’ is not defined

Setting up “export PYTHONPATH=/root/venv/lib/python2.6/site-packages” or “localhost ansible\_python\_interpreter=/root/venv/bin/python” in hosts makes the original error disappear but the resource doesn’t get created …

Here is the current error:

(venv)[root@test ansible]# ansible-playbook aws-cf-provision.yml -vv

PLAY [localhost] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

TASK: [Create VPC, internet gateway, route tables and security groups] \*\*\*\*\*\*\*\*  
 REMOTE\_MODULE cloudformation template=VPCStack.json state=present region=eu-west-1 stack\_name=VPCStack-dev2 aws\_access\_key=\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\* aws\_secret\_key==\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
failed: [localhost] =\> {“failed”: true}

FATAL: all hosts have already failed – aborting

PLAY RECAP \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
to retry, use: --limit @/root/aws-cf-provision.retry

localhost : ok=0 changed=0 unreachable=0 failed=1

(venv)[root@test ansible]# pip list  
ansible (1.9.0.1)  
argparse (1.3.0)  
awscli (1.7.18)  
bcdoc (0.13.0)  
boto (2.38.0)  
botocore (0.101.0)  
colorama (0.3.3)  
docutils (0.12)  
ecdsa (0.13)  
httplib2 (0.9)  
Jinja2 (2.7.3)  
jmespath (0.6.1)  
List (1.3.0)  
MarkupSafe (0.23)  
ordereddict (1.1)  
paramiko (1.15.2)  
pip (1.4.1)  
pyasn1 (0.1.7)  
pycrypto (2.6.1)  
python-dateutil (2.4.2)  
PyYAML (3.11)  
rsa (3.1.4)  
setuptools (0.9.8)  
simplejson (3.6.5)  
six (1.9.0)

It doesn’t even point out where the problem could be. Is there any way to find out?

PS: I tried to delete the python virtualenv and recreate it back but the issue still remains.

Regards,  
Constantin

---

<div class="post-metadata">

**Author:** ![Justin\_Phelps](https://avatars.discourse-cdn.com/v4/letter/j/6de8d8/32.png) [@Justin\_Phelps](https://forum.ansible.com/u/Justin_Phelps)\
**Post date:** [August 28, 2015, 9:41pm UTC](https://forum.ansible.com/t/cant-find-boto-for-ansible-ec2-module/13247/13 "2015-08-28T21:41:29Z")

</div>

I managed to fix this with these two tasks:

- name: Find the path to the python interpreter  
command: which python  
register: pythonpath  
when: lookup(‘env’, ‘CI’) == “true”

- name: Set python interpreter path when in CI  
set\_fact: ansible\_python\_interpreter={{ pythonpath.stdout }}  
when: lookup(‘env’, ‘CI’) == “true”

You would take out the when statements as they are specific to my testing environment.

---

<div class="post-metadata">

**Author:** ![James\_Martin1](https://avatars.discourse-cdn.com/v4/letter/j/0ea827/32.png) [@James\_Martin1](https://forum.ansible.com/u/James_Martin1)\
**Post date:** [August 29, 2015, 7:51pm UTC](https://forum.ansible.com/t/cant-find-boto-for-ansible-ec2-module/13247/14 "2015-08-29T19:51:26Z")

</div>

Yay, 2 year old thread :).

The way you solve this is by modifying your inventory for localhost with the proper setting:

`#inventory file localhost ansible_python_interpreter="/usr/bin/env python"`

This will automatically pick up the active virtualenv’s python interpreter and modules that you’ve installed there, including boto. You don’t need to run any tasks to discover the path to the python interpreter.

---

<div class="post-metadata">

**Author:** ![Justin\_Phelps](https://avatars.discourse-cdn.com/v4/letter/j/6de8d8/32.png) [@Justin\_Phelps](https://forum.ansible.com/u/Justin_Phelps)\
**Post date:** [August 30, 2015, 1:36am UTC](https://forum.ansible.com/t/cant-find-boto-for-ansible-ec2-module/13247/15 "2015-08-30T01:36:54Z")

</div>

Thanks James.

That is easier and I can confirm it works in CircleCI.

---

<div class="post-metadata">

**Author:** ![Alex\_Leonhardt](https://avatars.discourse-cdn.com/v4/letter/a/ec9cab/32.png) [@Alex\_Leonhardt](https://forum.ansible.com/u/Alex_Leonhardt)\
**Post date:** [August 30, 2015, 8:06am UTC](https://forum.ansible.com/t/cant-find-boto-for-ansible-ec2-module/13247/16 "2015-08-30T08:06:36Z")

</div>

I tried a pull request for the GCE modules (as example) to use /usr/bin/env python instead of a fixed /usr/bin/python but that was dismissed without real consideration of whether it actually be a good idea (or not) nor a detailed explanation as to why it was considered “bad”.

I don’t see why, when /usr/bin/env python will mostly be the correct python, it’s still being enforced to use /usr/bin/python 😕 .

Maybe someone here knows the inner details as to why??

Alex

---

<div class="post-metadata">

**Author:** ![Timothy\_Appnel1](https://avatars.discourse-cdn.com/v4/letter/t/278dde/32.png) [@Timothy\_Appnel1](https://forum.ansible.com/u/Timothy_Appnel1)\
**Post date:** [September 1, 2015, 1:49am UTC](https://forum.ansible.com/t/cant-find-boto-for-ansible-ec2-module/13247/17 "2015-09-01T01:49:38Z")

</div>

Ansible doesn’t use a fixed /usr/bin/python necessarily. If you set a different python interpreter via your inventory as Justin did here and keep the remotes files, you’ll notice that Ansible has replaced with /usr/bin/python with the python interpreter you have in your inventory.

_\> I don’t see why, when /usr/bin/env python will mostly be the correct python, it’s still being enforced to use /usr/bin/python 😕 ._

---

<div class="post-metadata">

**Author:** ![Troy\_Cauble](https://avatars.discourse-cdn.com/v4/letter/t/e0b2c6/32.png) [@Troy\_Cauble](https://forum.ansible.com/u/Troy_Cauble)\
**Post date:** [August 11, 2016, 6:34pm UTC](https://forum.ansible.com/t/cant-find-boto-for-ansible-ec2-module/13247/18 "2016-08-11T18:34:28Z")

</div>

What can I do if I’m not using an inventory file? I’m exec-ing from a script with “ansible-playbook -i , …”.

Also, the ansible and ansible-playbook scripts in my\_virtualenv\_dir/bin start with  
#!/my\_virtualenv\_dir/bin/python2

So they’re using the right python to start…

---

<div class="post-metadata">

**Author:** ![Troy\_Cauble](https://avatars.discourse-cdn.com/v4/letter/t/e0b2c6/32.png) [@Troy\_Cauble](https://forum.ansible.com/u/Troy_Cauble)\
**Post date:** [August 11, 2016, 9:57pm UTC](https://forum.ansible.com/t/cant-find-boto-for-ansible-ec2-module/13247/19 "2016-08-11T21:57:15Z")

</div>

I found the solution elsewhere you can set this via -e

-e ‘ansible\_python\_interpreter=“/usr/bin/env python”’
