Ansible from Zero: Inventory, Playbooks, and Modules
Learn Ansible from zero: build a host inventory, write your first playbook with modules, and run it over SSH with a dry-run check first instead of guessing.
Netbay Engineering
Netbay Engineering
On this page
Ansible is the closest most teams get to infrastructure automation that a junior engineer can read and trust on day one. It works over SSH, requires no agent installed on the target machine, and describes the desired end state in YAML playbooks that double as living documentation. If you administer even a handful of Linux VPS instances, Ansible turns one-off fixes into replayable, version-control-friendly operations you can run again next month with total confidence.
Why Ansible Fits Cloud VPS Work
Three properties explain why Ansible beat out heavier tools for a huge share of shops running a few dozen servers:
- **Agentless by default** — the control machine only needs SSH keys; nothing has to be pre-installed on fresh nodes.
- **Push model** — you, not agents polled by a server, decide when change happens.
- **Declarative modules** — most modules are idempotent, so re-running a playbook after a partial failure repairs instead of duplicates.
A new Ubuntu VPS boots with only SSH available, and that single property makes Ansible the natural next step. Your inventory, playbooks, and roles become the reusable face of the whole fleet, and new hardware joins the system by editing text files rather than by clicking through dashboards.
The Inventory
The inventory is simply the list of hosts plus the connection variables needed to reach them. An INI file is the friendliest starting point because it scales from two machines to two hundred without ceremony:
[webservers]
web01 ansible_host=10.0.0.11 ansible_user=deploy
web02 ansible_host=10.0.0.12 ansible_user=deploy
[databases]
db01 ansible_host=10.0.0.21 ansible_user=deploy
[all:vars]
ansible_python_interpreter=/usr/bin/python3
ansible_ssh_private_key_file=~/.ssh/netbayHere [webservers] and [databases] are groups that playbooks can target as a unit, which is the mental model that makes fleets manageable. The [all:vars] section sets defaults that every host inherits, so connection secrets live in one place. Pointing ansible_ssh_private_key_file at the same key you used to provision the machines on Netbay means playbooks run with zero extra SSH setup.
Playbooks and Modules
A playbook is a top-level list of plays; each play selects hosts and lists tasks. Modules are the small built-in operations Ansible runs — installing a package, nudging a service, writing a file. A minimal bootstrap playbook reads like an audit checklist you could show a colleague:
- name: Bootstrap web servers
hosts: webservers
become: true
tasks:
- name: Install nginx
ansible.builtin.apt:
name: nginx
state: present
- name: Start and enable nginx
ansible.builtin.service:
name: nginx
state: started
enabled: true
- name: Deploy the index page
ansible.builtin.copy:
content: "Welcome to the fleet"
dest: /var/www/html/index.htmlEach task names a module (apt, service, copy) and passes a small argument map. Because copying the same content twice is a no-op, this playbook is safe to run repeatedly — the core guarantee you want from any automation, and the topic of a later post in this series.
Running the Playbook
ansible-inventory -i hosts.ini --list
ansible-playbook -i hosts.ini --check -K playbooks/bootstrap.yml
ansible-playbook -i hosts.ini -K playbooks/bootstrap.ymlThe first command dumps the resolved inventory so you can confirm groups and variable inheritance before touching anything. The second is a dry run: Ansible reports per-host ok, changed, or failed tags for every task without modifying the systems. The third actually applies. Reading those three columns across your fleet is the fastest way to develop trust in what the tool will do, and it is the habit that separates careful automation from chaos.
Takeaway
Start small: one inventory, two playbooks, a handful of modules. The value compounds as the fleet grows because every host that joins the webservers group inherits the entire bootstrap for free. When you are ready to practice, spin up an Ubuntu instance on Netbay in under 60 seconds and run the playbook above against it — netbayhosts.in makes a great scratch lab for exactly this workflow.
Keep reading
Follow along on a real VPS
Deploy Linux in under 60 seconds
These guides are written against Ubuntu, Debian, and RHEL-family images — the same ones on NetBay.
Deploy an instance