Ansible is an agentless IT automation tool that uses SSH and YAML playbooks to configure servers, deploy applications, and orchestrate complex workflows. It requires no agents on managed nodes — just SSH access and Python. This guide installs Ansible on Ubuntu 26.04 LTS and runs a first playbook.

Tested and valid on:

  • Ubuntu 26.04 LTS

Prerequisites

  • Ubuntu 26.04 LTS (control node)
  • SSH access to managed nodes
  • Python 3 on managed nodes

Step 1 – Install Ansible

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

Step 2 – Install via PPA for Latest Version (optional)

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

Step 3 – Configure the Inventory File

sudo nano /etc/ansible/hosts

Add your managed nodes:

[webservers]
web1.example.com
web2.example.com

[databases]
db1.example.com ansible_user=ubuntu

Step 4 – Test Connectivity

ansible all -m ping
ansible webservers -m ping -u ubuntu

Step 5 – Run Ad-Hoc Commands

ansible webservers -m command -a 'uptime'
ansible all -m shell -a 'free -h'
ansible webservers -m apt -a 'name=nginx state=present' --become

Step 6 – Write Your First Playbook

cat > install_nginx.yml << 'EOF'
---
- name: Install and start Nginx
  hosts: webservers
  become: true
  tasks:
    - name: Install nginx
      apt:
        name: nginx
        state: present
        update_cache: true
    - name: Start nginx
      service:
        name: nginx
        state: started
        enabled: true
EOF
ansible-playbook install_nginx.yml

Step 7 – Use Ansible Vault for Secrets

ansible-vault create secrets.yml
# Enter your secrets, then reference them:
ansible-playbook deploy.yml --ask-vault-pass

Conclusion

Ansible is configured on Ubuntu 26.04 LTS. Build complex playbooks to automate your entire infrastructure: package installation, configuration management, user management, and multi-tier application deployments.