Installing Ansible on Ubuntu 24.04

Complete guide to setup and basic configuration.

file

Ansible is an open-source automation tool that lets you manage servers, deploy applications, configure systems, and run commands across dozens or hundreds of machines — all from a single control node, using nothing more than SSH. No agents needed on the remote hosts.

It's especially powerful for automating routine tasks on VPS or dedicated servers.

Installation

Ubuntu 24.04 ships with a recent version of Ansible directly in the official repositories — this is the cleanest and most recommended way.

  1. Update your package index and upgrade existing packages:
   sudo apt update
   sudo apt upgrade -y
  1. Install Ansible:
sudo apt install ansible -y
  1. Verify the installation:
ansible --version

Example output:

ansible [core 2.16.10]
config file = /etc/ansible/ansible.cfg
configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python3/dist-packages/ansible
ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections
executable location = /usr/bin/ansible
python version = 3.12.3 (main, Nov  6 2024, 20:26:53) [GCC 13.2.0]
jinja version = 3.1.2
libyaml = True

Setting up SSH access to managed hosts

Ansible connects over SSH, so you need passwordless access from the control node to every target host.

  1. Generate an SSH key pair (if you don’t have one yet):
ssh-keygen -t ed25519 -C "ansible@your-control-node"

Press Enter for all prompts (no passphrase for automation).
Or use RSA if ed25519 isn’t supported:

ssh-keygen -t rsa -b 4096 -C "ansible@your-control-node"
  1. Copy the public key to each managed host:
ssh-copy-id root@TARGET_IP

Or for a non-root user:

ssh-copy-id user@TARGET_IP

Enter the target host’s password once — after that, no more passwords needed.

  1. Create or edit the inventory file (list of hosts):
sudo mkdir -p /etc/ansible
sudo nano /etc/ansible/hosts

Example inventory:

[webservers]
web1 ansible_host=192.168.1.10 ansible_user=root
web2 ansible_host=192.168.1.11 ansible_user=root

[dbservers]
db1 ansible_host=192.168.1.20 ansible_user=root

[all:vars]
ansible_python_interpreter=/usr/bin/python3
  • Groups like [webservers] organize hosts
  • ansible_host = IP address
  • ansible_user = SSH login user
  • ansible_python_interpreter ensures Python 3 is used (important on Ubuntu 24.04)

Our products and services

Web HostingReliable hosting services for websites of any scale.
Order
VPSFlexible cloud infrastructure with full root access.
Order
Dedicated ServersBare metal servers for maximum performance.
Order
  1. Test connectivity:
ansible all -m ping

Successful output:

web1 | SUCCESS => {
    "changed": false,
    "ping": "pong"
}
web2 | SUCCESS => {
    "changed": false,
    "ping": "pong"
}

file Ansible ping module confirming connectivity

Quick tips & best practices

  • Ansible requires only SSH + Python on remote hosts — both are already present on Ubuntu 24.04.
  • Always use SSH keys (no passwords) for automation — it’s more secure and reliable.
  • Store your inventory and playbooks in Git — Ansible configs are plain YAML/text.
  • Start with small playbooks and use --check mode to test without making changes.

Help

If you have any questions or need assistance, please contact us through the ticket system — we're always here to help!

Need help?Our engineers will help you free of charge with any question in minutesContact us