Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ansible fails to find boto3 and botocore although installed

The following task:

  - name: Fetch dump file from S3
      aws_s3:
        bucket: mybucket
        object: somedump.sql
        dest: /tmp/somedump.sql
        mode: get
      delegate_to: "{{ ec2_instance_ip }}"

fails with:

fatal: [localhost -> 22.33.111.88]: FAILED! => {"changed": false, "msg": "boto3 and botocore required for this module"}

$ ssh [email protected]
$ pip freeze
boto3==1.7.41
botocore==1.10.41

$ pip3 freeze
blinker==1.3
boto3==1.7.41
botocore==1.10.41

The target machine is ubuntu/xenial so I have also taken care of installing python-minimal (given that out of the box the machine only had python3)

Therefore, on the target machine:

$(which python) --version
Python 2.7.12

I have run the above play with and without appending:

  vars:
    ansible_python_interpreter: /usr/bin/python3

at the end of the task...

like image 275
pkaramol Avatar asked Jun 20 '18 17:06

pkaramol


People also ask

Is Botocore same as Boto3?

Botocore. Boto3 is built atop of a library called Botocore, which is shared by the AWS CLI. Botocore provides the low level clients, session, and credential & configuration data. Boto3 builds on top of Botocore by providing its own session, resources and collections.

How do I know what version of Boto3 I have?

All AWS services and arguments are now available to your Lambda function. Tip: Use print(boto3. __version__) and print(botocore. __version__) in your function code to confirm the version of Boto 3 and Botocore.


2 Answers

Could you try to downgrade "boto3" package to see if there is no issue there?

Get available versions:

pip install boto3==some_nonsense_word

Then:

pip uninstall boto3

Finally:

pip install boto3==<VERSION>

Answer based on the findings from the following GitHub issue comment:

https://github.com/ansible/ansible-modules-core/issues/2014#issuecomment-144620598

like image 91
Rezney Avatar answered Oct 18 '22 01:10

Rezney


I had the same problem on MacOS and downgrading didn't fix the issue. However, adding the following python path to a hosts file fixed the issue:

[local]
localhost              ansible_connection=local     ansible_python_interpreter=/usr/local/bin/python3

Afterwards, you can run your ansible playbook with the hosts as:

ansible-playbook -i ./hosts playbook.yml

Or you set the path to python in the execution:

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

If you're on Mac and you have installed other copies of python via homebrew, you can run these commands to install boto to the system python:

sudo /usr/bin/python -m easy_install pip
sudo /usr/bin/python -m pip install boto

Here are more solutions to the issue: https://github.com/ansible/ansible/issues/15019

like image 33
Rene B. Avatar answered Oct 18 '22 03:10

Rene B.