How To Install Ansible In Amazon Linux

How To Install Ansible In Amazon Linux

Reading time1 min
#Automation#Cloud#Linux#Ansible#AmazonLinux#AWS

Mastering Automation: How to Install Ansible on Amazon Linux for Streamlined Infrastructure Management

Automation has become the backbone of efficient IT operations, and Ansible stands out as one of the go-to tools to simplify complex infrastructure tasks. If you’re managing cloud environments on Amazon Web Services (AWS), using Amazon Linux instances is a common choice for its seamless integration and optimized performance.

But here’s the catch — many tutorials overlook the nuances of Amazon Linux’s ecosystem. The way you install and configure Ansible on Amazon Linux differs slightly from other Linux distributions, mainly due to its unique package repositories and system setup.

In this blog post, I’ll guide you through a precise, foolproof method to install Ansible on Amazon Linux (both Amazon Linux 1 and Amazon Linux 2). You’ll avoid guesswork around dependencies or compatibility issues, enabling you to start automating your infrastructure quickly and reliably.


Why Choose Ansible on Amazon Linux?

Before we jump into installation, here’s why this setup matters:

  • Native Integration: Amazon Linux is tailored for AWS environments, offering better stability and security.
  • Optimized Performance: Using the official repositories ensures you get updates suitable for your instance.
  • Reducing Manual Errors: With Ansible installed properly, repetitive configuration tasks become automated.
  • Boosted Productivity: Automate everything from EC2 setups to application deployments within minutes.

Preparing Your Environment

For this guide, I assume you have access to an Amazon EC2 instance running either Amazon Linux AMI (Amazon Linux 1) or Amazon Linux 2. You can connect using SSH like so:

ssh -i your-key.pem ec2-user@your-instance-address

Once connected, ensure your system packages are up-to-date:

sudo yum update -y

Installing Ansible on Amazon Linux 2

Amazon Linux 2 doesn’t include Ansible in its default repos by default. However, thanks to the Extra Packages for Enterprise Linux (EPEL) repository mirroring in AWS repos, it’s straightforward.

Step 1: Enable EPEL Repository

First we need access to EPEL packages because Ansible isn’t part of the standard emirates repo:

sudo amazon-linux-extras install epel -y

Alternatively, check if it's enabled already by running:

amazon-linux-extras | grep epel

Step 2: Install Ansible

Now install Ansible via yum:

sudo yum install ansible -y

Step 3: Verify Installation

Check the installed version:

ansible --version

You should see output like:

ansible [core 2.x.x] 
  config file = /etc/ansible/ansible.cfg
  ...

Installing Ansible on Amazon Linux AMI (Amazon Linux 1)

Older Amazon Linux versions don’t support amazon-linux-extras so installation varies slightly.

Step 1: Enable EPEL Repository Manually

Add EPEL repo RPM manually as follows:

sudo yum install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-6.noarch.rpm

Step 2: Install Python & Pip

Ansible requires Python; often Python is pre-installed but let's ensure pip is ready:

sudo yum install python-pip -y
sudo pip install --upgrade pip

Alternatively, if Python isn't installed yet:

sudo yum install python -y

Step 3: Install Ansible Using Pip

Because EPEL can sometimes be outdated for older systems, using pip ensures you get a recent version.

sudo pip install ansible --upgrade

Step 4: Confirm Installation

Same as before,

ansible --version

Quick Test: Ping Your EC2 Hosts with Ansible

Let’s verify everything works end-to-end. On your control node (the one where you installed ansible), create a simple inventory file:

hosts.ini

[local]
127.0.0.1 ansible_connection=local

[ec2_instances]
ec2-instance-ip-address ansible_user=ec2-user ansible_ssh_private_key_file=/path/to/your/key.pem 

Replace ec2-instance-ip-address with your target host IP or DNS name.

Run a simple ping module test highlighting connectivity:

ansible all -i hosts.ini -m ping

Expected output if successful:

127.0.0.1 | SUCCESS => {
    "changed": false,
    "ping": "pong"
}

ec2-instance-ip-address | SUCCESS => {
    "changed": false,
    "ping": "pong"
}

This confirms your setup is ready for more advanced playbooks!


Troubleshooting Common Pitfalls on Amazon Linux

  • Package Not Found: Ensure EPEL repo is enabled correctly by re-running amazon-linux-extras commands or reinstalling EPEL rpm.
  • SSH Connection Errors: Make sure your key permissions are secure (chmod 400 your-key.pem) and that security group allows SSH from your IP.
  • Python Version Issues: Some older Amazon LC instances use Python 2; upgrading to Python3 might be necessary for certain modules.

Wrapping Up

Getting Ansible up-and-running on Amazon Linux doesn’t have to involve guesswork or cumbersome workarounds. By following this guide—which leverages native repos like amazon-linux-extras and handles the quirks of both Amazon Linux versions—you can streamline automation workflows effortlessly.

With Ansible installed precisely as shown above, you’re equipped to automate deployments, configuration management, and orchestrate complex cloud setups with minimal manual errors.

If you found this practical walkthrough helpful or want me to cover writing real-world playbooks next, drop a comment below!

Happy automating! 🚀