LEARNING PATH  ›  Ansible Fundamentals
LEVEL 01 / BEGINNER~60–90 MIN
● YOUR FIRST CONFIGURATION AUTOMATION

Configure your first Linux servers.

Use Ansible to connect to two existing Ubuntu or Debian servers, install Nginx, and ensure the service is running. Learn inventory, SSH, YAML playbooks, modules and idempotency through one guided lab.

ANSIBLE
inventory.ini
SSH connection
site.yml
Ubuntu hosts
02Managed Linux servers
03Core project files
01 → 02One playbook configures both
02 / ARCHITECTURE

How the lab works

Ansible runs on your control node and connects to managed servers over SSH. It reads the inventory to identify hosts and the playbook to determine what configuration to apply.

01 · CONTROL NODEAnsible installed
02 · INVENTORYLists web1 and web2
03 · SSHSecure remote access
04 · MANAGED HOSTSNginx installed and running
CONTROL NODE

Your computer / Linux environment

Stores Ansible, the inventory, configuration and playbook. It initiates connections to the managed hosts.

MANAGED NODES

Two existing Ubuntu/Debian servers

Receive tasks over SSH. Ansible installs Nginx and makes sure its service is enabled and started.

03 / BEFORE YOU START

Prepare your lab environment

This project configures existing machines. It does not create cloud infrastructure or virtual machines.

Control node

Linux or macOS environment with Ansible installed, terminal access and an SSH client. Windows users can use WSL2.

Managed nodes

Two running Ubuntu/Debian servers, reachable over SSH, with Python 3 available and a user authorised to use sudo.

Important: You need two reachable servers and valid SSH credentials before running the playbook. Replace all example IP addresses with your own. Do not publish private SSH keys.

Install Ansible on the control node

On an Ubuntu control node, install Ansible using the distribution package manager:

Terminal · Ubuntu control node
sudo apt update
sudo apt install ansible -y
ansible --version

For other operating systems, follow the official Ansible installation guide.

04 / PROJECT FILES

Build the three project files

Create one folder and add the configuration, inventory and playbook. Select each tab to inspect its contents and copy the code.

Project directory structure
ansible-beginner/
├── ansible.cfg
├── inventory.ini
└── site.yml
ansible.cfg

ansible.cfg

Sets the default inventory file and keeps SSH host-key verification enabled.

inventory.ini

Defines the webservers group, server addresses, SSH user and private-key path.

site.yml

Describes the desired server state: Nginx installed, enabled and running.

Why YAML?

YAML is a human-readable data format used here to express Ansible plays, tasks and module parameters.

05 / COMMAND WALKTHROUGH

Run the automation step by step

Run these commands from inside the ansible-beginner directory on your control node.

Step 1 — Create the project folder

mkdir ansible-beginner
cd ansible-beginner

Create the three files shown in the Project Files section and paste in their contents.

Step 2 — Generate an SSH key

ssh-keygen -t ed25519 -f ~/.ssh/ansible_lab

Use a passphrase if appropriate for your environment. The public key ends in .pub; keep the private key protected.

Step 3 — Copy the public key to each host

ssh-copy-id -i ~/.ssh/ansible_lab.pub automation@SERVER_1_IP
ssh-copy-id -i ~/.ssh/ansible_lab.pub automation@SERVER_2_IP

Replace the placeholders with the actual addresses. Confirm each host's SSH fingerprint before accepting it.

Step 4 — Test SSH and Ansible connectivity

ssh -i ~/.ssh/ansible_lab automation@SERVER_1_IP
ansible webservers -m ansible.builtin.ping

Repeat the SSH test for the second host. Ansible's ping module checks remote Ansible execution and should return pong for each host.

Step 5 — Check the playbook syntax

ansible-playbook site.yml --syntax-check

Fix YAML indentation or syntax errors before running tasks.

Step 6 — Execute the playbook

ansible-playbook site.yml

Ansible connects to both managed nodes, installs Nginx and ensures the service is enabled and started. The SSH user must have working sudo access.

06 / VERIFY & CLEAN UP

Confirm the desired state

Check Ansible connectivity again

ansible webservers -m ansible.builtin.ping

Check that Nginx is active

ansible webservers -b -m ansible.builtin.command -a "systemctl is-active nginx"

Both hosts should report active. You can also open each server's IP address in a browser if inbound HTTP traffic on port 80 is allowed.

Understand idempotency: Run ansible-playbook site.yml a second time. If the servers already match the desired state, Ansible should report no further changes for those tasks.

Troubleshooting guide

UNREACHABLE

Check IP address, network route, SSH service, firewall rules and key authentication.

Permission denied

Check the SSH username, public-key installation and file permissions on the private key.

sudo failure

Confirm the remote account is authorised to use sudo and that the privilege escalation settings match the host.

Module / Python error

Confirm Python 3 is available on each managed node and that the target OS is supported.

Cleanup: This lab does not provision servers, so Ansible has no cloud resources to destroy. If you created temporary virtual machines specifically for the lab, shut them down or delete them using the platform that created them after confirming they are no longer needed.
07 / KNOWLEDGE CHECK

Test what you've learned

Answer these questions to check your understanding of the beginner lab.

1. What does the inventory file define?
2. What does become: true enable?
3. What is idempotency?
4. Does Ansible's ping module send a normal ICMP ping?