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.
Installing Ansible on Ubuntu
Step 1: Update the System
Ensure your Ubuntu system is up-to-date:sudo apt update && sudo apt upgrade -yStep 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/ansibleStep 3: Install Ansible
Install Ansible using theapt package manager:
sudo apt install -y ansibleStep 4: Verify the Installation
Check the installed Ansible version:ansible --versionStep 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.pemSee also: Automating Jenkins Installation with Ansible
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: distRun the playbook:
ansible-playbook -i /etc/ansible/hosts update-packages.ymlExample: 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: yesCommon Use Cases for Ansible on Ubuntu
- Server Configuration:
- Application Deployment:
- Infrastructure Management:
- Compliance Enforcement:
See also: How to Install Ansible on Ubuntu 23.10 Mantic Minotaur
Best Practices for Using Ansible on Ubuntu
- Secure Connections:
- Use Variables:
vars:
package_name: nginx
- Leverage Roles:
roles/
├── common/
│ ├── tasks/
│ │ └── main.yml
│ └── vars/
│ └── main.yml
- Test Playbooks:
--check mode to validate playbooks before execution:
ansible-playbook playbook.yml --check
- Monitor Performance:
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
See also: Can Ansible Automate Windows? Complete WinRM + SSH Setup Guide (2026)
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 --versionMethod 2: PPA (latest version)
sudo apt-add-repository --yes --update ppa:ansible/ansible
sudo apt install -y ansibleMethod 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 ansibleMethod 4: pipx (isolated)
sudo apt install -y pipx
pipx install ansible-core
pipx inject ansible-core ansibleVersion 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 -20Configure 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 pingManage 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: presentUbuntu 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
Category: installation