Ansible is an open-source automation engine for provisioning, configuration management, application deployment, and orchestration. It uses YAML playbooks and runs over SSH鈥攏o agents on target hosts. Ansible is written in Python, uses a simple push-based model, and works on Linux, macOS, and Windows (with the right setup). In this guide you install and configure Ansible on Rocky Linux 8, AlmaLinux 8, or CentOS 8, then test connectivity to a remote host.
In this guide you’ll:
- Update the system and install Python 3 (and optionally pip)
- Install Ansible from the EPEL repository (recommended) or via pip
- Generate an SSH key and use
ssh-copy-idfor passwordless access to a target host - Create an inventory file and run the ping module, then run a command with privilege escalation (
--ask-become-pass)
Related: Ansible on Rocky Linux/AlmaLinux 9 路 Python 2 and 3 on Rocky Linux/CentOS 8 路 Python on Fedora 35 路 Ansible on Fedora 35
Prerequisites
- A machine running Rocky Linux 8, AlmaLinux 8, or CentOS 8 (control node).
- Root or sudo access.
- Internet access to install packages and EPEL.
- A remote host (Linux) reachable by SSH for testing (optional but recommended).
- Basic familiarity with the Linux terminal and SSH.
Table of contents
- Ensure the system is up to date
- Install Python 3 (and pip)
- Install Ansible
- Test the Ansible installation
1. Ensure the system is up to date
Update installed packages:
| |
2. Install Python 3 (and pip)
Ansible requires Python 3 (or Python 2 on older setups; Python 2 is end-of-life, so use Python 3). Rocky Linux 8 and AlmaLinux 8 ship with Python 3. Install it and pip (needed if you install Ansible via pip later):
| |
Optional: upgrade pip for the current user only (avoids affecting system Python): python3 -m pip install --user --upgrade pip. Using sudo pip3 install --upgrade pip can interfere with system-managed packages.
3. Install Ansible
You can install Ansible from the EPEL repository (simplest) or with pip.
Option A: Install Ansible from EPEL (recommended)
EPEL (Extra Packages for Enterprise Linux) provides additional packages for RHEL-based systems. Enable EPEL, then install Ansible:
| |
Verify the installation:
| |
EPEL typically provides Ansible 2.9.x. For a newer ansible-core (Ansible 2.14+), you can use the official Ansible repository or pip.
Option B: Install Ansible with pip
To install the latest Ansible for the current user:
| |
Ensure ~/.local/bin is in your PATH so the ansible command is found. Alternatively, use a virtual environment to isolate the install.
4. Test the Ansible installation
Ansible connects to hosts over SSH. For a smooth experience, set up passwordless SSH from the control node to the target host.
Generate an SSH key and copy it to the remote host
Generate a key (accept defaults or set a passphrase):
| |
Copy your public key to the remote host (replace user and IP with yours):
| |
Create an inventory file and run the ping module
Create a simple inventory file (e.g. hosts) listing the target host and the SSH user:
| |
Or use a path in your project directory and reference it with -i hosts. Example content (use ansible_user on newer Ansible; ansible_ssh_user is deprecated but still works):
| |
Test connectivity with the ping module:
| |
SUCCESS and "ping": "pong" mean Ansible can reach the host.
Run a command with privilege escalation (sudo)
For tasks that need root on the remote host, use become (e.g. sudo). The --ask-become-pass option prompts for the remote user’s sudo password:
| |
The -b flag enables privilege escalation (equivalent to become: yes in a playbook). Ansible may warn that you should use become, become_method, and become_user in playbooks instead of running sudo inside the command; for ad-hoc commands, -b --ask-become-pass is fine. If you use a password and don’t have sshpass installed, Ansible will prompt for the SSH password as well unless you use SSH keys.
Example output (target may already have the package):
| |
Frequently Asked Questions (FAQ)
What is Ansible?
Ansible is an automation tool that configures systems, deploys software, and orchestrates tasks using YAML playbooks. It connects to hosts over SSH (or WinRM on Windows) and does not require an agent on target machines.
Do I need Python on the control node only or on the targets too?
The control node (where you run ansible) needs Python and Ansible. Managed hosts (Linux) need Python 2.6+ or 3.5+ so Ansible can run modules there. Most current Linux distros already have Python 3 installed.
What is the difference between EPEL and pip for installing Ansible?
EPEL gives you a stable, distro-packaged version (often Ansible 2.9.x) that is easy to upgrade with dnf. pip lets you install a specific or newer version (e.g. ansible-core 2.14+) for the current user or in a virtual environment.
How do I specify the SSH user for a host in the inventory?
Use ansible_user=username (or the deprecated ansible_ssh_user=username) in the inventory next to the host, or set remote_user in a playbook. For privilege escalation, use ansible_become=true, ansible_become_method=sudo, and optionally ansible_become_pass (or prompt with --ask-become-pass).
Conclusion
You installed Ansible on Rocky Linux 8, AlmaLinux 8, or CentOS 8 using EPEL or pip, set up SSH key-based access to a remote host, created an inventory file, and tested connectivity with the ping module and a command using become (-b --ask-become-pass). For the same steps on Rocky Linux 9 / AlmaLinux 9, see How to Install and Configure Ansible on Rocky/Alma Linux 9. For configuration management with Puppet, see Puppet 7 on Rocky Linux/CentOS 8.