Ansible is an agentless IT automation tool that manages servers and deploys applications using simple YAML playbooks over SSH. This guide installs Ansible on Ubuntu 24.04 LTS and demonstrates a basic playbook.
Tested and valid on:
- Ubuntu 24.04 LTS
Prerequisites
- Ubuntu 24.04 LTS control node
- SSH access to managed nodes
- A user with sudo privileges
Step 1 – Add the Ansible PPA
The Ubuntu 24.04 repos include Ansible, but the PPA has the latest version:
sudo add-apt-repository --yes --update ppa:ansible/ansible
Step 2 – Install Ansible
Install:
sudo apt install ansible -y
Step 3 – Verify the Installation
Check the version:
ansible --version
Step 4 – Configure the Inventory
Add managed hosts to the default inventory:
sudo nano /etc/ansible/hosts
Add:
[webservers]
192.168.1.100
192.168.1.101
[dbservers]
192.168.1.200
Step 5 – Test Connectivity
Ping all hosts:
ansible all -m ping
Step 6 – Write a Simple Playbook
Create nginx.yml:
---
- name: Install and start Nginx
hosts: webservers
become: true
tasks:
- name: Install Nginx
apt:
name: nginx
state: present
update_cache: yes
- name: Start and enable Nginx
service:
name: nginx
state: started
enabled: yes
Step 7 – Run the Playbook
Execute the playbook:
ansible-playbook nginx.yml
Add -v, -vv, or -vvv for verbose output.
Conclusion
Ansible is now installed on Ubuntu 24.04 LTS and ready to automate your infrastructure. Write idempotent playbooks to configure servers consistently and use Ansible Vault to encrypt secrets.