Last Updated on 2 days by Sachin G
Ansible is one of the most popular automation tools for Linux system administrators and DevOps engineers. Whether you’re deploying applications, managing configurations, or orchestrating IT infrastructure, installing Ansible on CentOS, RHEL, AlmaLinux, or Rocky Linux is often the first step toward streamlining your workflow.
If you’re completely new to Ansible, I’ve already covered the basics—including what Ansible is, how it works, and why it’s essential—in our article From Sysadmin to DevOps: Introduction to Ansible. You may want to start there before diving into installation, so you’ll have a clear understanding of the core concepts before getting hands-on.
In this guide, we’ll walk you through:
- Installing Ansible on different RHEL-based systems.
- Multiple methods, including Yum/DNF, EPEL repository, and offline installation.
- How to install specific Ansible versions for compatibility.
- Best practices and real-world tips from production environments.
Prerequisites
Before you start, ensure:
- You have root or sudo access.
- Your system is connected to the internet (unless using the offline method).
- Your system package manager is Yum (CentOS/RHEL) or DNF (AlmaLinux/Rocky).
Method 1: Install Ansible on CentOS/RHEL using Yum
This is the simplest and most recommended method for CentOS 8 Stream and CentOS 9 Stream.
sudo yum install epel-release -y
- EPEL stands for Extra Packages for Enterprise Linux.
- This repository contains additional packages, including Ansible, that are not in the default RHEL/CentOS repositories.
- This command downloads and installs the repository configuration file so your system knows where to get these extra packages.
The below command will install the Ansible package and all its dependencies from the enabled repositories (including EPEL).
sudo yum install ansible -y
Method 2: Install Ansible on AlmaLinux & Rocky Linux using DNF
For AlmaLinux 9 and Rocky Linux 9, DNF is the default package manager. dn
f The next-generation version of yum (used in RHEL 8, CentOS 8, AlmaLinux, Rocky Linux).Works the same way as yum but with better performance and dependency resolution.
sudo dnf install epel-release -y
sudo dnf install ansible -y
Method 3: Install a Specific Version of Ansible
Sometimes you need an older Ansible version for compatibility (e.g., Ansible 2.9 on RHEL 8). In some environments, you may need a specific Ansible version for compatibility with older playbooks, CI/CD pipelines, or enterprise-approved configurations. While yum
or dnf
Sometimes allows version selection, many RHEL-based repositories only provide the latest version, making pip
a better choice for version control.
Step 1: Install pip
If pip
is not already installed, install it with:
sudo yum install python3-pip -y
or on newer RHEL-like systems:
sudo dnf install python3-pip -y
This ensures you can install Python-based packages directly from PyPI.
Step 2: Install a Specific Ansible Version
Use pip to install the desired version:
pip3 install ansible==2.9.27
Replace 2.9.27
with the version you require.
Method 4: Install Ansible Without Internet (Offline)
For air-gapped environments, download RPMs on a machine with internet access:
# Download Ansible RPM packages without installing them
yum install --downloadonly --downloaddir=ansible_pkgs ansible
# Compress the downloaded RPMs into a single tar.gz archive
tar -czvf ansible_pkgs.tar.gz ansible_pkgs
ansible_pkgs
directory.Transfer the archive to the offline server and run:
# Install Ansible from local RPM files (offline installation)
yum localinstall ansible_pkgs/*.rpm
Verify Installation:
Checks if Ansible is installed and displays the installed version, configuration file location, and Python interpreter path.
ansible --version
Example output:
ansible [core 2.14.18]
config file = /etc/ansible/ansible.cfg
configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python3.9/site-packages/ansible
ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections
executable location = /usr/bin/ansible
python version = 3.9.21 (main, Jun 27 2025, 00:00:00) GCC 11.5.0 20240719 (Red Hat 11.5.0-5)
jinja version = 3.1.2
libyaml = True
From working on Ansible Red Hat installation guide projects, I’ve learned:
“Always match your Ansible version with the environment’s requirements. Installing the latest version isn’t always the best choice for production stability.”
One common challenge is forgetting to enable the EPEL repository, which causes installation to fail with package not found errors.
FAQ – Installing Ansible on CentOS/RHEL-like OS
A: Use the Red Hat Automation Hub or enable the official Ansible Automation Platform repository.
A: Use:
sudo dnf install epel-release -y && sudo dnf install ansible -y
A: Yes, but it’s better to use your distribution’s package manager for system-wide use.
A: Use:
sudo yum install ansible- -y
A: Not by default—you need EPEL or Red Hat’s official automation repositories.
A: The commands are almost identical—only the package manager name (Yum/DNF) changes.
Whether you are on CentOS, RHEL, AlmaLinux, or Rocky Linux, installing Ansible is straightforward with Yum/DNF. By following best practices—like using the correct repository and version—you can avoid common pitfalls.
Want to learn more about Ansible?
Please explore our complete Ansible Tutorials for Beginners to master automation step-by-step.
You can also check out our Recommended Ansible Courses for expert-led training and practical projects to boost your skills.
I’m Sachin Gupta — a freelance IT support specialist and founder of techtransit.org. I’m certified in Linux, Ansible, OpenShift (Red Hat), cPanel, and ITIL, with over 15 years of hands-on experience. I create beginner-friendly Linux tutorials, help with Ansible automation, and offer IT support on platforms like Upwork, Freelancer, and PeoplePerHour. Follow Tech Transit for practical tips, hosting guides, and real-world Linux expertise!