Ansible Curriculum
Installing Ansible
Ansible Configuration
SSH Setup for Ansible
On this page
Subtopic•Installing Ansible

Install Linux

Linux systems are the most common platforms for Ansible control nodes. While you can install Ansible using Python's package manager, installing it using your operating system's native package manager is convenient because it handles system-level dependencies (such as the OpenSSH client) automatically.

In this guide, we will cover how to install Ansible on Debian/Ubuntu systems, enable repositories and install on Red Hat Enterprise Linux (RHEL)/CentOS systems, verify the installation, and analyze the output of the configuration path variables.

Installation Commands Summary

Linux DistributionPackage ManagerRepository Setup commandInstallation command
Ubuntuaptsudo apt-add-repository ppa:ansible/ansiblesudo apt install ansible
DebianaptEdit /etc/apt/sources.list with Debian PPAsudo apt install ansible
CentOS / RHEL 7yumsudo yum install epel-releasesudo yum install ansible
RHEL 8 / 9dnfsudo subscription-manager repos --enable=...sudo dnf install ansible
FedoradnfEnabled by defaultsudo dnf install ansible

1. Installing on Ubuntu and Debian

Ubuntu maintains a dedicated Personal Package Archive (PPA) to distribute the latest stable versions of Ansible.

Ubuntu Installation:

# 1. Update system package index
sudo apt update

# 2. Install software-properties-common for repository management
sudo apt install -y software-properties-common

# 3. Add the official Ansible PPA repository
sudo apt-add-repository --yes --update ppa:ansible/ansible

# 4. Install the Ansible package
sudo apt install -y ansible

2. Installing on CentOS and Red Hat Enterprise Linux (RHEL)

RHEL 8 / 9 Installation:

On Red Hat Enterprise Linux, the Ansible packages are distributed through official subscription repositories. You must enable the correct repository before running the installation command.

# 1. Enable the Ansible repository
# For RHEL 8:
sudo subscription-manager repos --enable=ansible-2.9-for-rhel-8-x86_64-rpms

# For RHEL 9:
sudo subscription-manager repos --enable=ansible-2-for-rhel-9-x86_64-rpms

# 2. Install using dnf
sudo dnf install -y ansible

CentOS 7 / 8 Installation:

CentOS uses the EPEL (Extra Packages for Enterprise Linux) repository to host Ansible packages.

# 1. Install the EPEL release repository package
sudo yum install -y epel-release

# 2. Update the package index
sudo yum update -y

# 3. Install the Ansible package
sudo yum install -y ansible

3. Verifying the Installation

After the installation completes, verify that the binary is available and configuration paths are resolved correctly by running:

ansible --version

Output:

ansible [core 2.15.3]
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/home/ubuntu/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3/dist-packages/ansible
  ansible collection location = /home/ubuntu/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/bin/ansible
  python version = 3.10.12 (main, Jul  5 2023, 18:54:27) [GCC 11.2.0] (/usr/bin/python3)
  jinja version = 3.0.3
  libyaml = True

Verify these key parameters in the output:

  • config file: The active configuration file (defaults to /etc/ansible/ansible.cfg unless overridden).
  • executable location: The path to the Ansible binary (confirm it points to the expected system directory).
  • python version: The Python interpreter version used by the control node.

Summary

Ansible can be installed on Linux using native package managers like apt or dnf. By adding the official repositories, you can install the latest stable version and verify your installation using the ansible --version command. In the next section, we will cover installing Ansible on macOS.

←Previous ModuleIntroduction to Ansible