Loading...

Watch: Configure a Python Virtual Environment for Ansible AWS - ansible collection amazon.aws

Learn to configure a Python Virtual Environment for Ansible AWS amazon.aws collection using the latest Python 3.8 and boto3 library releases.

How to configure a Python Virtual Environment for Ansible AWS?

Using a Python Virtual Environment is a convenient way to maintain up-to-date Python dependency of the Ansible collection amazon.aws without interfering with your Linux system.

This initial configuration sometimes is a roadblock for some AWS users to start using Ansible.

I’m Luca Berton and welcome to today’s episode of Ansible Pilot.

Links

  • [Ansible collection amazon.aws](https://docs.ansible.com/ansible/latest/collections/amazon/aws/index.html)
  • [Python boto3](https://aws.amazon.com/it/sdk-for-python/)

Playbook

Configure a Python Virtual Environment for Ansible AWS:

  • boto3

How to Python Virtual Environment for Ansible AWS.

I’m going to show you how to configure a Python Virtual Environment for Ansible AWS to successfully use the Ansible collection amazon.aws of modules and plugins to manage various operations related to AWS infrastructure such as EC2, VPC, Security Groups, etc.

Ansible AWS modules are written on top of boto3. Boto3 is the Python SDK for the AWS that allows users to manage AWS infrastructure: EC2, VPC, Security Groups, etc.

code

``bash

$ python3.8 -m venv venv

$ source venv/bin/activate

(venv) $ pip3.8 install --upgrade pip

(venv) $ pip3.8 install boto3

(venv) $ ansible-galaxy collection install amazon.aws

`

execution

``bash

$ ansible --version

ansible [core 2.12.2]

config file = /etc/ansible/ansible.cfg

configured module search path = ['/home/devops/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']

ansible python module location = /usr/lib/python3.8/site-packages/ansible

ansible collection location = /home/devops/.ansible/collections:/usr/share/ansible/collections

executable location = /usr/bin/ansible

python version = 3.8.12 (default, Sep 16 2021, 10:46:05) [GCC 8.5.0 20210514 (Red Hat 8.5.0-3)]

jinja version = 2.10.3

libyaml = True

[devops@demo ~]$ whereis python

python: /usr/bin/python3.6 /usr/bin/python3.6m /usr/bin/python3.8 /usr/lib/python3.6 /usr/lib/python3.8 /usr/lib64/python3.6 /usr/lib64/python3.8 /usr/local/lib/python3.8 /usr/include/python3.6m /usr/include/python3.8 /usr/share/man/man1/python.1.gz

[devops@demo ~]$ python3.8 -m venv venv

[devops@demo ~]$ source venv/bin/activate

(venv) [devops@demo ~]$ pip3.8 install --upgrade pip

Collecting pip

Using cached https://files.pythonhosted.org/packages/96/2f/caec18213f6a67852f6997fb0673ae08d2e93d1b81573edb93ba4ef06970/pip-22.1.2-py3-none-any

Read the full tutorial: Configure a Python Virtual Environment for Ansible AWS - ansible collection amazon.aws