How to Install Ansible on Ubuntu 24.04 (Step-by-Step Guide)

ansible automation ubuntu server

Ansible is one of the most popular open-source automation tools used for configuration management, application deployment, and infrastructure orchestration. It is agentless, easy to learn, and widely adopted by system administrators, DevOps engineers, and IT operations teams.

With the release of Ubuntu 24.04 LTS (Noble Numbat), many users are looking for a reliable and up-to-date way to install Ansible while ensuring long-term stability and security.

In this guide, you will learn multiple methods to install Ansible on Ubuntu 24.04, including:

  • Installing from the official Ubuntu repository
  • Installing the latest version via Ansible PPA
  • Installing Ansible using Python pip
  • Verifying the installation
  • Basic post-installation checks and best practices

What Is Ansible and Why Use It?

Ansible is an automation engine that allows you to manage servers and applications using simple YAML-based playbooks.

Key Benefits of Ansible

  • Agentless architecture (uses SSH)
  • Simple YAML syntax
  • Idempotent operations
  • Strong community and enterprise support
  • Ideal for automation at scale

Ansible is commonly used for:

  • Server provisioning
  • Configuration management
  • Application deployment
  • Cloud automation
  • CI/CD pipelines

System Requirements

Before installing Ansible, ensure your system meets the following requirements:

  • Ubuntu 24.04 LTS
  • Python 3.10 or later (installed by default)
  • Sudo or root privileges
  • Internet connection

You can confirm your Ubuntu version by running:

lsb_release -a

Method 1: Install Ansible from the Official Ubuntu Repository

This is the simplest and most stable method, recommended for most users who prioritize reliability over having the latest features.

Step 1: Update System Packages

sudo apt update
sudo apt upgrade -y

Step 2: Install Ansible

sudo apt install ansible -y

Step 3: Verify Installation

ansible --version

You should see output similar to:

ansible [core 2.x.x]
python version = 3.x

✅ This confirms Ansible has been installed successfully.

Pros

  • Easy to install
  • Stable and well-tested

Cons

  • Version may not be the latest

Method 2: Install the Latest Ansible Using Official PPA (Recommended)

If you need the latest Ansible features, installing via the official Ansible PPA is the best choice.

Step 1: Install Required Dependencies

sudo apt install software-properties-common -y

Step 2: Add Ansible PPA Repository

sudo add-apt-repository --yes --update ppa:ansible/ansible

Step 3: Install Ansible

sudo apt install ansible -y

Step 4: Check Ansible Version

ansible --version

This method ensures you are running the latest stable Ansible release compatible with Ubuntu 24.04.

Method 3: Install Ansible Using pip (Python Package Manager)

This method is suitable for developers, virtual environments, or CI/CD pipelines.

Step 1: Install Python pip

sudo apt install python3-pip -y

Step 2: Install Ansible via pip

pip3 install --user ansible

Step 3: Add Local Binary Path (If Needed)

echo 'export PATH=$PATH:$HOME/.local/bin' >> ~/.bashrc
source ~/.bashrc

Step 4: Verify Installation

ansible --version

Pros

  • Latest version available
  • Isolated per user

Cons

  • Not system-wide
  • Requires manual path management

Verify Ansible Installation

Once installed, run a simple test:

ansible localhost -m ping

Expected output:

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

This confirms Ansible is working properly.

Understanding Ansible Configuration Files

Default Configuration File Location

/etc/ansible/ansible.cfg

Inventory File

/etc/ansible/hosts

Example inventory:

[webservers]
192.168.1.10
192.168.1.11

Basic Ansible Commands for Beginners

Check Hosts Connectivity

ansible all -m ping

Run a Shell Command

ansible all -m shell -a "uptime"

Gather System Facts

ansible all -m setup

Common Issues and Troubleshooting

Issue 1: Command Not Found

ansible: command not found

Solution

  • Ensure Ansible is installed
  • Check PATH variable
  • Log out and log back in

Issue 2: Python Version Conflict

Ensure Python 3 is used:

ansible --version

Ubuntu 24.04 uses Python 3 by default, so this issue is rare.

Issue 3: SSH Authentication Errors

Make sure:

  • SSH keys are configured
  • Target host allows SSH access
  • Correct user is specified

Example:

ansible all -u ubuntu -m ping

Best Practices for Ansible on Ubuntu 24.04

  • Use SSH keys, not passwords
  • Store playbooks in Git repositories
  • Use roles for modular automation
  • Test playbooks with --check mode
  • Separate production and staging inventories

Example check mode:

ansible-playbook site.yml --check

When Should You Use Ansible Core vs Ansible Community?

  • Ansible Core: Minimal engine, faster, suitable for automation pipelines
  • Ansible Community: Includes collections and plugins, ideal for full automation

Most users should start with Ansible Community.

Conclusion

Installing Ansible on Ubuntu 24.04 is straightforward and flexible, depending on your needs. Whether you choose the official repository for stability, the PPA for the latest features, or pip for development environments, Ansible remains one of the most powerful automation tools available today.

If you are working in IT Operations or DevOps, mastering Ansible will significantly improve your efficiency and infrastructure reliability.

(Visited 1 times, 1 visits today)

You may also like