Deploy Python3, Docker, and Docker compose on Amazon Linux instance on AWS using Ansible.

Introduction

This is a hands-on demonstration of installing python3, docker, and docker-compose on an Amazon Linux instance on AWS using Ansible. You will need an AWS account and a host machine with Ansible installed to follow along. I used a Windows machine's Linux subsystem (WSL 2) to carry out this project.

Ansible is an open-source IT automation and configuration management tool. It is widely used to automate repetitive tasks, manage configurations, and orchestrate complex workflows across multiple systems. Ansible is simple to use, agentless, and highly extensible, making it popular for managing infrastructure and deploying applications.

Log in to your AWS account, click on the ec2 service, and select the Amazon Linux instance.

Select your preferred instance type, and create the key pair to ssh into the instance, then launch instance.

Connected to the Amazon Linux instance

I created the inventory file to get the details of the managed servers, and I added the SSH private key location to be able to connect to the instance.

When the ansible-playbook file is deployed without the become: yes command, an error is thrown by the ansible-playbook. This shows that the root user must be used for the installation.

Hence, the command is added to ensure that the ansible-playbook is successful.

The ansible.cfg file

The interpreter_python = /usr/bin/python3 is added to ensure that the Red Hat Enterprise Linux (RHEL) distro for Amazon Linux is used globally.

Before docker was installed and after installing python3, docker, and docker-compose on the Amazon Linux instance:

ansible-playbook deploy-docker.yaml

Afterwards, the ec2-user was added and redis was pulled using a docker command.

Thank you for reading. Please follow, like, comment, and share for a wider reach and more DevOps-related articles.

To access this code you can visit my GitHub account: https://github.com/gbejula/ansible-docker