Last Updated on 4 weeks by Sachin G

This guide walks you through how to install Ansible on Ubuntu, specifically versions 22.04 LTS and 25.04, using beginner-friendly, step-by-step instructions. You’ll also get real-world tips, common pitfalls to avoid, and practical use cases.

Ansible, an open-source automation tool, simplifies the management of complex systems and streamlines IT operations. Installing and configuring Ansible on Ubuntu empowers users to automate repetitive tasks efficiently.

All screenshots in this tutorial are from real setups. It’s written based on practical experience — not just theory.

Why Use Ansible with Ubuntu?

Ansible is an automation tool for automating server setup, app deployment, and configuration management. Ubuntu, maintained by Canonical, is widely trusted by system administrators, cloud engineers, and DevOps teams.

  • Pairing them gives you:
  • Quick YAML playbook execution
  • A consistent environment
  • Simple command-line usage
  • Easier SSH integration

It is agentless, which means that it does not require any package to be installed on the managed systems. Ansible uses simple, explanatory language to define the desired state of the system. This makes it easy to simple and use, and it is a good choice for both beginners and experienced IT professionals.

Prerequisites for Installing Ansible on Ubuntu

Before installing Ansible, ensure the following Ubuntu Ansible prerequisites are met:

  • A running Ubuntu 22.04 LTS or 25.04 system (fresh VPS or local VM is fine)
  • A non-root user with sudo privileges
  • OpenSSH server installed and enabled
  • Internet access (for package downloads)

Learn Smarter. Level Up Faster →

Want to master Linux, DevOps, Ansible, or Cloud workflows the smart way? I’ve curated a list of top-rated, real-world Udemy courses — based on student reviews and practical feedback.

Visit the Recommended Courses page to explore and enroll in courses trusted by the community.

See Curated Courses →

Step-by-Step Ansible Setup on Ubuntu

Step 1: Update the package

The first step is to update the package index on your server. This will ensure that you have the latest versions of all the packages that depend on.

# sudo apt update

Step 2: Option 1: Install Ansible Using APT on Ubuntu 22.04

This is the most straightforward way.

The installation process for Ansible on Ubuntu 22.04 is straightforward. Use the appropriate package manager to install Ansible, ensuring access to the latest stable release and required dependencies. Once the package repository is updated, you can proceed to install Ansible using the following command:

# sudo apt update
# sudo apt install ansible -y

This installs the latest version available in Ubuntu’s official repositories.

Installation

Option 2: Install and Configure Ansible from PPA in Ubuntu 25.04

If you’re on Ubuntu 25.04 or want the latest Ansible version:

sudo apt update
sudo apt install software-properties-common -y
sudo add-apt-repository --yes --update ppa:ansible/ansible
sudo apt install ansible -y

This pulls the latest Ansible release from the official PPA maintained by Ansible contributors.

Step 3: Verify Version

The below command will check the version with other configurations and module path.

# ansible --version

Configure Ansible Control Node on Ubuntu

Ansible works by running commands from a control node over SSH to managed nodes (other servers or machines). Ansible uses a configuration file located at /etc/ansible/ansible.cfg. You can modify this file to customize the behavior of Ansible according to your needs. However, most configurations can be left at their default settings for basic use.

SSH Setup for Ansible Ubuntu:

ssh-keygen
ssh-copy-id user@managed-node-ip

Once SSH access is set up, you can create an inventory file.

Ansible Inventory Configuration

An inventory file defines which systems Ansible will manage. Ansible needs an inventory file to explain the hosts it manages. The default location of the inventory file is at /etc/ansible/hosts. You can edit this file to add your server’s IP address or hostname.

vim /etc/ansible/hosts
[webgroup]
192.168.1.15
192.168.1.16

[dbgroup]
192.168.1.21

You can organize servers by groups (webservers, databases, etc.) for better control.

VerifyAnsible Connectivity

Once you have set the inventory file, you can test Ansible connectivity to your server using the ping :

ansible all -m ping

The above command sends a ping request to all hosts defined in the inventory file and verifies if Ansible can connect to them successfully then the reply or output will be in pong.

Ansible Command-Line Setup & First YAML Playbook

Create your first playbook:

# install_apache.yaml
- hosts: webservers
  become: yes
  tasks:
    - name: Install Apache
      apt:
        name: apache2
        state: present

Run it:

ansible-playbook install_apache.yaml

YAML makes it easy to define tasks that are readable and repeatable.

During testing on Ubuntu 25.04, the add-apt-repository command failed due to a missing package on a minimal VPS setup. This reminded us that not all Ubuntu setups come pre-equipped for PPA installs — always install software-properties-common first.

Also, inconsistent SSH keys caused failed connections. A simple ssh -vv user@host helped debug the issue — something no guide told us upfront.

Real-World Use Cases

  • Automating LAMP stack setup for multiple servers
  • Daily package updates across a fleet of Ubuntu machines
  • Deploying and restarting services (like NGINX) remotely
  • Cloud provisioning with AWS or DigitalOcean using Ansible modules

For deeper learning, we recommend courses on Udemy .

By following these steps, you can do an Ansible installation on Ubuntu.

FAQ: Installing and Using Ansible on Ubuntu

Q1: What’s the difference between the control node and managed node?

The control node runs Ansible commands. Managed nodes receive those commands via SSH.

Q2: Can I install Ansible on Windows?


Yes, using WSL (Windows Subsystem for Linux) or with brew install ansible on macOS.

Q3: Do I need Python installed on managed nodes?

Yes — Python 3 is required (but usually pre-installed on Ubuntu).

Q4: Can I install Ansible on Ubuntu 25.04?


Yes — but use the Ansible PPA for the most up-to-date version.

Q5: What is the easiest way to install Ansible on Ubuntu?


Use APT for stable Ubuntu versions like 22.04:
sudo apt install ansible -y

You can also refer to our latest post regarding ansible navigator .