Home > front end >  boto3 and botocore are required for this module in jenkins pipeline
boto3 and botocore are required for this module in jenkins pipeline

Time:11-19

I am trying to run ansible playbook via jenkins groovy scripts but keep getting error: boto3 is required. I have already installed boto3:

pip list boto | grep boto
boto3                             1.20.3
botocore                          1.23.3

I have inventory as:

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

Python:

which python
/usr/bin/python

pip:

 which pip
/home/john/.local/bin/pip

boto:

find $HOME/.local -name 'boto3' -type d/home/john/.local/lib/python3.6/site-packages/boto3

versions:

pip --version
pip 21.3.1 from /home/john/.local/lib/python3.6/site-packages/pip (python 3.6)

python --version
Python 3.6.9

Ansible:

which ansible
/usr/bin/ansible

Playbook in sh file:

ansible-playbook -c local \
    -e ansible_python_interpreter=$(which python) \
    -i localhost, \
    -e env="'${ENV}'" \
    -e image="'${IMAGE_NAME}'" \
    -e version="'${BUILD_NUMBER}'" \
    infra/test.ansible.yaml

What else did I miss to configure?

CodePudding user response:

Finally after days of struggle fixed my problem using the steps below:

  1. Created virtual environment for python, boto and ansible

  2. Edit the ansible inventory file to point the interpreter to python instead of /usr/bin/python

    sudo pip install virtualenv sudo pip install boto botocore source ansible_vEnv/bin/activate

Set the following in ansible inventory:

[localhost]
localhost ansible_python_interpreter=python
  1. Gave the playbook command as ansible-playbook -c local dir/test.yaml

Note: make sure you use boto in yaml file and not boto3:

- hosts: localhost
  gather_facts: no
  tasks:
  - name:
    pip:
      name: boto // here
      state: present

Pointing the interpreter to python will actually pickup the python from our isolated environment i.e. virtual environment we created in step 2.

  • Related