Ansible Installation

Ansible is an agentless configuration management tool that manages servers over SSH. Where manual administration requires logging into each server individually, Ansible lets you run the same task across 100 servers simultaneously. The agentless design is a key advantage: no software needs to be installed on managed nodes, only Python (which is on every Ubuntu server). The control node (where Ansible runs) only needs SSH access to the managed nodes.

What is Ansible?

Ansible architecture (agentless):

  Control Node (your workstation or jump server):
    Ansible installed here
    Has SSH keys to all managed nodes
         |
         | SSH (port 22)
         |
  Managed Nodes (your servers):
    No Ansible agent installed
    Only needs: Python 3, SSH server
    web-01, web-02, db-01, db-02 ...

  Ansible connects → runs Python code → disconnects
  No daemon, no background process on managed nodes

Installing Ansible

# Install from official PPA (newer than Ubuntu's repos):
sudo apt update
sudo apt install -y software-properties-common
sudo add-apt-repository --yes --update ppa:ansible/ansible
sudo apt install -y ansible

# Verify installation:
ansible --version

ansible --version output

ansible [core 2.16.6]
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/root/.ansible/plugins/modules']
  python version = 3.12.3
  jinja version = 3.1.3
# Set up SSH key authentication to managed nodes (required):
ssh-keygen -t ed25519 -C "ansible-control"    # Generate key if needed
ssh-copy-id irfan@web-01    # Copy public key to managed node
ssh-copy-id irfan@web-02

# Test SSH access (Ansible uses SSH):
ssh irfan@web-01 "hostname"

Inventory configuration

nano /etc/ansible/hosts

/etc/ansible/hosts — inventory file

[webservers]
web-01 ansible_host=192.168.1.10 ansible_user=irfan
web-02 ansible_host=192.168.1.11 ansible_user=irfan

[databases]
db-01 ansible_host=192.168.1.20 ansible_user=irfan

[production:children]    # Group of groups
webservers
databases

[all:vars]               # Variables for all hosts
ansible_python_interpreter=/usr/bin/python3
ansible_ssh_private_key_file=~/.ssh/ansible_key
# Test connectivity to all hosts:
ansible all -m ping

ansible ping output

web-01 | SUCCESS => {
    "changed": false,
    "ping": "pong"
}
web-02 | SUCCESS => {
    "changed": false,
    "ping": "pong"
}

Ad-hoc commands

# Run a command on all webservers:
ansible webservers -m command -a "uptime"

# Run with sudo:
ansible webservers -m command -a "df -h" --become

# Gather facts about hosts:
ansible web-01 -m setup | grep ansible_os_family

# Install a package on all hosts:
ansible all -m apt -a "name=nginx state=present update_cache=yes" --become

# Restart a service:
ansible webservers -m service -a "name=nginx state=restarted" --become

# Copy a file to all hosts:
ansible webservers -m copy -a "src=/etc/nginx/nginx.conf dest=/etc/nginx/nginx.conf" --become

Conclusion

The ansible all -m ping test is the baseline for verifying your inventory and SSH setup. Run it after adding new hosts to confirm connectivity before writing playbooks. The --become flag runs tasks with sudo — add it whenever you need root privileges. Ad-hoc commands are great for one-off tasks; for anything you will repeat, write a playbook (covered in the Ansible Playbooks article) to make the task idempotent and documented.

FAQ

Is Ansible Installation important for Ubuntu administrators?+

Yes. It supports practical Ubuntu administration because it connects directly to server reliability, security, troubleshooting, or daily operations.

Should I practice this on a live server?+

Use a lab VM first. After you understand the command output and rollback path, apply the workflow carefully on real systems.

What should I do after reading this article?+

Run the practice commands, write down what each one shows, and continue to the next article in the Ubuntu roadmap.

Need help with Ubuntu administration?

Work directly with Muhammad Irfan Aslam for Ubuntu Server, Linux, cloud, Docker, DevOps, CI/CD, or infrastructure troubleshooting support.

Hire Me for Support