Skip to content

How to install Ansible on Ubuntu 18.04 for IT automation

Updated 2 min read

Updated: 28 September 2026 · Applies to: Ansible (ansible-core 2.16+) on Ubuntu 24.04, Debian 12, AlmaLinux 9 and Rocky Linux 9

Ubuntu 18.04 is end of life; these steps are for Ubuntu 24.04. Ansible automates server configuration over SSH, without an agent on the servers.

Install Ansible on your control machine

sudo apt install ansible                      # Ubuntu 24.04 / Debian 12 (distribution version)
sudo add-apt-repository ppa:ansible/ansible && sudo apt install ansible   # Ubuntu: latest version
sudo dnf install ansible-core                  # AlmaLinux / Rocky 9
pipx install --include-deps ansible            # any system, latest version, per user

Check with ansible --version. Only the control machine needs Ansible; managed servers need SSH and Python 3.

Inventory and first commands

Create inventory.ini:

[web]
web1.example.com
web2.example.com ansible_port=2222

[db]
db1.example.com

[all:vars]
ansible_user=admin
ssh-copy-id admin@web1.example.com                  # key login to each server
ansible all -i inventory.ini -m ping
ansible web -i inventory.ini -a "uptime"
ansible web -i inventory.ini -b -m ansible.builtin.package -a "name=nginx state=present"

A playbook

# site.yml
- hosts: web
  become: true
  tasks:
    - name: Install nginx
      ansible.builtin.package:
        name: nginx
        state: present
    - name: Start nginx
      ansible.builtin.service:
        name: nginx
        state: started
        enabled: true
ansible-playbook -i inventory.ini site.yml --check    # dry run
ansible-playbook -i inventory.ini site.yml

Related services

KVM VPS hosting

NVMe SSD and full root access, with Free Basic Managed Support.

Unmanaged dedicated servers

full root access and free IPMI KVM, with Free Basic Managed Support.

Linux server management

hardening, patching, monitoring and automation for Ubuntu, Debian, RHEL and AlmaLinux.

Was this answer helpful?

Still stuck? Open a ticket