How to Install Ansible on Amazon Linux 2 Instance

How to Install Ansible on Amazon Linux 2 Instance

How to Install Ansible on Amazon Linux 2 Instance

Dear Reader, I hope you are doing fantastic today. In some of my previous posts, I have covered how to install Docker, OpenJDK 11, Nginx, Apache Web Server, Git etc. on an Amazon Linux 2 EC2 Instance.

In this post, I will show you how to install Ansible on Amazon Linux 2 EC2 instance in a simple and step-by-step manner.

So are you ready?

Alright, let’s start.

Don’t want to miss any posts from us? join us on our Facebook group, and follow us on Facebook, Twitter, LinkedIn, and Instagram. You can also subscribe to our newsletter below to not miss any updates from us.

A bit on Amazon Linux 2 and Ansible

Amazon Linux 2: Amazon Linux 2 is a Linux operating system provided by AWS itself.

  • Amazon Linux 2 is designed for performance and is supported until June 30, 2025
  • Compatible with a wide range of software
  • Easy to use with a CLI and GUI
  • Amazon Linux 2 is based on the Red Hat Enterprise Linux (RHEL) distribution.
  • You can use yum package manager to install packages on it.

Ansible:

Ansible is an open-source automation platform that enables Infrastructure as Code.

  • Supports hybrid cloud automation
  • Edge Automation
  • Network/Security Automation
  • Configuration management etc.

Background on Installing Ansible on Amazon Linux 2

When it comes to installing Ansible on Amazon Linux 2, there are quite a few ways. At least I have tried 3 different ways that I am gonna share with you today.

  1. Install Ansible on Amazon Linux 2 using Amazon Linux Extras Repo
  2. Install Ansible on Amazon Linux 2 Using EPEL Repository
  3. Install Ansible on Amazon Linux 2 using pip

I personally always prefer installing from Amazon Linux Extras as it’s pretty straightforward. However, you might not get the version that you looking for in it. So use any of the three methods that suit your need.

Prerequisite

Steps to Install Ansible on Amazon Linux 2 Instance

Here are the steps you can perform to install Ansible on an Amazon Linux 2 EC2 instance. I have broken it into very very small steps to keep it very simple.

  1. Launch an Amazon Linux 2 EC2 Instance
  2. Connect to your Instance
  3. Update Available Package
  4. Install Ansible on Amazon Linux 2
  5. Verify Ansible Installation
  6. Run a Simple Ansible Playbook

Step 1: Launch an Amazon Linux 2 EC2 Instance

If you already have an up-and-running Amazon Linux 2 instance, feel free to move straight to step 2.

Otherwise, you can create an Amazon Linux 2 instance using one of my previous tutorials: Launch an EC2 Instance in AWS Step by Step

To launch an Amazon Linux 2 instance, just make sure you have chosen Amazon Linux 2 AMI shown below-

How to Install Ansible on Amazon Linux 2 Instance 1

Step 2: Connect to your Instance

You can connect to your EC2 Linux system from your local system using an SSH client.

Here is the command for that-

ssh -i /path/key-pair-name.pem instance-user-name@instance-public-dns-name

However, I always prefer to use the EC2 instance connect feature as it is easy peasy.

Select your Ec2 instance and click Connect.

How to Install Ansible on Amazon Linux 2 Instance 2

Verify the user name and click Connect again. Within no time, you should be in your EC2 instance.

Step 3: Update the Available Package

Before you install anything, it’s best to run a system update to update all the available packages to the latest.

sudo yum update
Run System Update

Step 4: Install Ansible on Amazon Linux 2

As we talked earlier, I will show you 3 different ways to install Ansible on your Linux 2 EC2 Instance. Let’s begin.

Method 1: Install Ansible using Amazon Linux Extras

1. Find ansible in the amazon-linux-extras repository

amazon-linux-extras list | grep ansible
Ansible in AMazon Linux Extras

2. Install Ansible using sudo amazon-linux-extras install ansible2 -y

sudo amazon-linux-extras install ansible2 -y
Install Ansible in Linux 2 from Amazon Linux Extras

As you can see in the screenshot above, Ansible 2.9.23 is installed on our Amazon Linux 2. Let’s move ahead to method 2.

Note: If you need to uninstall it, run sudo amazon-linux-extras remove ansible2 -y

Method 2: Install Ansible on Amazon Linux 2 using EPEL Repository

EPEL stands for Extra Packages for Enterprise Linux. It basically provides high-quality community-managed software packages that you can install easily.

1. Install Epel on Amazon Linux 2

sudo amazon-linux-extras install epel -y

Above command will install and enable Epel on Amazon Linux 2.

2. Check available packages in epel

sudo yum list | grep epel

3. Disable ansible2 Topic in Amazon Linux Extras

If you try to install Ansible from epel using sudo yum –enablerepo epel install ansible, it gets ignored and the ansible available in amazon-linux-extras starts getting installed.

To avoid that, first, disable the asnible2 topic in amazon-linux-extras and then in the next step, you can install Ansible using epel.

sudo amazon-linux-extras disable ansible2

4. Install Ansible using epel

sudo yum --enablerepo epel install ansible -y
Ansible using EPEL

I have not provided -y option just to check where it is getting installed from. And as you can see it is getting installed from epel as highlighted.

5. Uninstall Ansible using epel (optional)

sudo yum --enablerepo epel remove ansible

Method 3: Install Ansible on Amazon Linux 2 using pip

Well if you see Ansible’s official installation instructions, it recommends installing it using pip – a package manager for Python packages.

And shall I tell you? Ansible is built on Python or written in Python.

1. Install Python 3

sudo yum install python3

2. Search for pip in yum

yum search pip

3. Install pip3

sudo yum install python3-pip

4. Check pip version

pip3 --version

5. Install Ansible using pip

pip install ansible
lnstall ansible using pip

As you can see pip installed Ansible 2.11.12. Which is quite the latest version. Also, the deprecation warning says to use Python 3.8 or more.

You can install Python 3.8 using

sudo amazon-linux-extras install python3.8

Step 5: Verify Ansible Installation

No matter which method you have used to install Ansible on your Linux 2 EC2 instance. You can verify your Ansible installation using the below command-

ansible --version
Install Ansible in Amazon Linux 2 from Amazon Linux Extras

Congratulations!!!

You have successfully installed Ansible on your Amazon Linux 2 EC2 Instance.

Conclusion

In this how-to guide, you learnt How to Install Ansible on Amazon Linux 2 Instance

We covered-

  • Knowing Amazon Linux 2 and Ansible.
  • Launched an Amazon Linux 2 EC2 instance and connected to it.
  • Installed Ansible using 3 different ways.
  • Verified Ansible Installation.

Were you able to install Ansible on Amazon Linux 2 instance using this tutorial? Let me know in the comment section.

Enjoyed the content?

Subscribe to our newsletter below to get awesome AWS learning materials delivered straight to your inbox.

Don’t forget to motivate us-

Suggested Read:

One thought on “How to Install Ansible on Amazon Linux 2 Instance

Leave a Reply

Your email address will not be published. Required fields are marked *