‘boto3 and botocore are required for this module’ error in Ansible on RHEL 7.6

1 minute read

Fixing the error “boto3 and botocore are required for this module” when running an Ansible playbook on a RHEL 7 server

Today I was runng into issues on my RHEL 7 server when trying to deploy CloudFormation on AWS using an Ansible playbook. After a couple minutes of consulting with the Stack Overflow gods, I decided to run a yum update on my server.

I then proceeded to run my playbok WHICH RAN PERFECTLY EVERYTIME for the last week, only this time I was met with this output:

TASK [Provisioning in AWS using cloudformation template] *********************************
fatal: [localhost]: FAILED! => {"changed": false, "msg": "boto3 and botocore are required for this module"}

I knew boto3 and botocore were installed, because running the below told me so:

pip freeze|grep boto

boto==2.49.0
boto3==1.10.49
botocore==1.13.49

The Fix

Virtualenv to the rescue!

Virtualenv allows you to create a virtual environment with Python installed. You can create multiple, one for each project, side-byside. This allows project environment variables to remain seperate.

  • I installed virtualenv with:
$ sudo pip install virtualenv
  • Create a directory:
$ mkdir ~virtualenvironment
  • Create a folder in the directory for your project
$ virtualenv ~/virtualenvironment/project
  • cd into ~/virtualenvironment/project/bin and run:
source activate
  • You will see (project) before the shell prompt if it worked.
  • install boto3 and botocore while in the new environment
$ pip install boto3
$ pip install botocore
  • Now I open my Ansible inventory host file and define the path to the python interperter:
localhost ansible_connection=local ansible_python_interpreter=/home/jtracy/virtualenvironment/aws/bin/python2.7

It should look like this:

My Image