Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ansible ec2: "boto required for this module"

Tags:

ansible

boto

When I run this simple Ansible playbook:

- name: EC2 Test Example
  hosts: localhost
  connection: local
  gather_facts: False

  tasks:
  - name: EC2 Instance
    ec2:
      # Amazon EC2 key pair name
      key_name: my-key-pair
      # Amazon EC2 Security Group
      group: my-security-group
      instance_type: t2.micro
      # Latest from https://wiki.debian.org/Cloud/AmazonEC2Image/Jessie
      image: ami-221ea342
      wait: yes
    register: ec2

I run with venv/bin/ansible-playbook -i localhost, playbook.yml:

PLAY [EC2 Test Example] ********************************************************

TASK [EC2 Instance] ************************************************************
fatal: [localhost]: FAILED! => {"changed": false, "failed": true, "msg": "boto required for this module"}
    to retry, use: --limit @/Users/admin/temp/ansec2/playbook.retry

PLAY RECAP *********************************************************************
localhost                  : ok=0    changed=0    unreachable=0    failed=1

So obviously, I have boto installed in the venv that I'm using as well as my default system Python:

➜  ansec2 venv/bin/pip list
Package         Version 
--------------- --------
ansible         2.2.1.0 
boto            2.45.0  
boto3           1.4.4   
botocore        1.5.4   
...

I've read a few similar posts and I don't see a working solution.

like image 549
clay Avatar asked Jan 21 '17 01:01

clay


2 Answers

The root cause of your problem is the -i localhost, hack. You don't need to use it anymore in Ansible.

You can just run:

ansible-playbook playbook.yml

And with connection: local in the play Ansible will use the Python executable set by venv.


When you use the -i localhost, hack, Ansible calls its default /usr/bin/python.

In this case you still can add the ansible_python_interpreter parameter to tell Ansible to use this specific environment:

ansible-playbook -i localhost, playbook.yml --extra-vars "ansible_python_interpreter=/Users/admin/temp/ansec2/venv/bin/python" 

But I think you should avoid it and use the first method.

like image 141
techraf Avatar answered Sep 19 '22 03:09

techraf


In my case the message was because I was missing boto, although I had boto3. So I did pip install boto and that fixed it.

like image 41
nettie Avatar answered Sep 22 '22 03:09

nettie