AnsiblePilot — Master Ansible Automation

AnsiblePilot is the leading resource for learning Ansible automation, DevOps, and infrastructure as code. Browse over 1,400 tutorials covering Ansible modules, playbooks, roles, collections, and real-world examples. Whether you are a beginner or an experienced engineer, our step-by-step guides help you automate Linux, Windows, cloud, containers, and network infrastructure.

Popular Topics

About Luca Berton

Luca Berton is an Ansible automation expert, author of 8 Ansible books published by Apress and Leanpub including "Ansible for VMware by Examples" and "Ansible for Kubernetes by Example", and creator of the Ansible Pilot YouTube channel. He shares practical automation knowledge through tutorials, books, and video courses to help IT professionals and DevOps engineers master infrastructure automation.

Can Ansible Run on Ubuntu? Install & Configure Ansible on Ubuntu (Guide)

By Luca Berton · Published 2024-01-01 · Category: installation

Yes, Ansible runs on Ubuntu. How to install Ansible on Ubuntu 22.04, 24.04, and 25.04 via apt, pip, or PPA. Configure and manage remote hosts from Ubuntu.

Ansible is a widely used automation tool that runs seamlessly on Ubuntu, making it an excellent choice for managing infrastructure and applications. This article explores how to install and use Ansible on Ubuntu to simplify automation workflows.

Can Ansible Run on Ubuntu?

Yes, Ansible runs perfectly on Ubuntu, both as a control node (where Ansible is installed and executed) and as a managed node (where Ansible performs tasks). Its compatibility with Ubuntu's package management system and extensive module library ensures efficient automation on Ubuntu systems.

Key Features:

Native Support: Available in Ubuntu’s default repositories. • Cross-Platform Management: Manage Ubuntu alongside other operating systems. • Rich Module Library: Includes modules tailored for Ubuntu-based tasks.

See also: Automating Jenkins Installation with Ansible

Installing Ansible on Ubuntu

Step 1: Update the System

Ensure your Ubuntu system is up-to-date:
sudo apt update && sudo apt upgrade -y

Step 2: Add the Ansible PPA (Optional)

To get the latest Ansible version, add the official Ansible PPA:
sudo apt install -y software-properties-common
sudo add-apt-repository --yes --update ppa:ansible/ansible

Step 3: Install Ansible

Install Ansible using the apt package manager:
sudo apt install -y ansible

Step 4: Verify the Installation

Check the installed Ansible version:
ansible --version

Step 5: Configure the Inventory File

The default inventory file is located at /etc/ansible/hosts. Add your managed nodes:
[ubuntu_servers]
192.168.1.10 ansible_user=ubuntu ansible_ssh_private_key_file=/path/to/key.pem

Running Ansible Playbooks on Ubuntu

Example: Updating Packages

Create a playbook to update all packages on Ubuntu servers:
- name: Update Ubuntu packages
  hosts: ubuntu_servers
  tasks:
    - name: Update APT cache
      apt:
        update_cache: yes

- name: Upgrade all packages apt: upgrade: dist

Run the playbook:

ansible-playbook -i /etc/ansible/hosts update-packages.yml

Example: Installing Software

Create a playbook to install Nginx on Ubuntu:
- name: Install Nginx on Ubuntu
  hosts: ubuntu_servers
  tasks:
    - name: Install Nginx
      apt:
        name: nginx
        state: present

- name: Start and enable Nginx service: name: nginx state: started enabled: yes

See also: How to Install Ansible on Ubuntu 23.10 Mantic Minotaur

Common Use Cases for Ansible on Ubuntu

Server Configuration: Automate server setup, including user management, firewall rules, and software installation. Application Deployment: Deploy web applications, databases, and services efficiently. Infrastructure Management: Manage cloud instances, Docker containers, or Kubernetes clusters on Ubuntu. Compliance Enforcement: Ensure servers adhere to organizational security policies.

Best Practices for Using Ansible on Ubuntu

Secure Connections: Use SSH keys for authentication and encrypt sensitive data with Ansible Vault. Use Variables: Parameterize playbooks to adapt to different environments:
   vars:
     package_name: nginx
   
Leverage Roles: Organize complex playbooks into reusable roles for better maintainability:
   roles/
   ├── common/
   │   ├── tasks/
   │   │   └── main.yml
   │   └── vars/
   │       └── main.yml
   
Test Playbooks: Use --check mode to validate playbooks before execution:
   ansible-playbook playbook.yml --check
   
Monitor Performance: Track execution times and resource usage to optimize playbooks.

See also: Can Ansible Automate Windows? Complete WinRM + SSH Setup Guide (2026)

Conclusion

Ansible is an excellent automation tool for Ubuntu, enabling you to manage infrastructure and applications with ease. Its integration with Ubuntu's ecosystem, combined with its powerful features, makes Ansible a go-to solution for automation on Ubuntu systems.

Learn More About Ansible on Ubuntu

Yes — Ubuntu is a First-Class Ansible Platform

Ubuntu is one of the most popular platforms for running Ansible as both controller and managed host.

Install Ansible on Ubuntu

Method 1: apt (system package)

sudo apt update
sudo apt install -y ansible
ansible --version

Method 2: PPA (latest version)

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

Method 3: pip (recommended for latest)

sudo apt install -y python3-pip python3-venv
python3 -m venv ~/ansible-venv
source ~/ansible-venv/bin/activate
pip install ansible

Method 4: pipx (isolated)

sudo apt install -y pipx
pipx install ansible-core
pipx inject ansible-core ansible

Version Comparison

| Method | Version | Updates | |--------|---------|---------| | apt (default) | Older (distro pinned) | With OS updates | | PPA | Latest stable | Frequent | | pip | Latest | pip install --upgrade ansible |

Verify Installation

ansible --version
ansible localhost -m ping
ansible localhost -m setup | head -20

Configure for Remote Management

# Create project
mkdir ~/ansible-project && cd ~/ansible-project

# Create inventory cat > inventory.yml << 'EOF' all: hosts: web1: ansible_host: 192.168.1.10 web2: ansible_host: 192.168.1.11 vars: ansible_user: deploy ansible_python_interpreter: /usr/bin/python3 EOF

# Create ansible.cfg cat > ansible.cfg << 'EOF' [defaults] inventory = inventory.yml host_key_checking = False interpreter_python = auto_silent EOF

# Test connectivity ansible all -m ping

Manage Other Ubuntu Hosts

---
- name: Configure Ubuntu servers
  hosts: all
  become: true
  tasks:
    - name: Update packages
      ansible.builtin.apt:
        upgrade: dist
        update_cache: true
        cache_valid_time: 3600

- name: Install common tools ansible.builtin.apt: name: - vim - curl - htop - git state: present

Ubuntu Version Support

| Ubuntu | Ansible Controller | Managed Host | |--------|-------------------|-------------| | 24.04 LTS | ✅ | ✅ | | 22.04 LTS | ✅ | ✅ | | 20.04 LTS | ✅ | ✅ | | 25.04 | ✅ | ✅ |

FAQ

Can Ubuntu be both controller and managed host?

Yes — Ubuntu commonly serves as the Ansible controller (where you run playbooks) AND as a managed host (configured by Ansible).

Do I need Python on managed Ubuntu hosts?

Yes — Python 3 is required. Ubuntu includes it by default. If missing: sudo apt install python3

WSL2 Ubuntu as Ansible controller?

Yes — Ansible works perfectly in WSL2 Ubuntu for managing remote servers.

Related Articles

Ansible Vault guideAnsible Docker patternsstatic and dynamic Ansible inventoryAnsible Nginx role examplerole dependencies in Ansible

Category: installation

Browse all Ansible tutorials · AnsiblePilot Home