Ansible Basics
Agentless configuration management: pushing the same setup over SSH to every server in your inventory.
On this page5 sections
Where Terraform's job is usually provisioning - creating the VM, the network, the database - Ansible's job is typically configuration: once a server exists, making sure it has the right packages, files, and services running.
Agentless, over SSH
Tools like Puppet or Chef require installing a permanent agent on every managed machine. Ansible doesn't - it connects over plain SSH (the same protocol you already know from earlier lessons), runs what it needs to, and leaves nothing permanently installed behind. One less piece of software to patch and secure on every server you manage.
Inventory
An inventory file lists every host Ansible manages, usually grouped by role:
[webservers]
web1.example.com
web2.example.com
[databases]
db1.example.com
A single command can then target "every webserver" or "every host" without naming each one individually.
Playbooks
A playbook is a YAML file listing the tasks to run, in order:
- hosts: webservers
tasks:
- name: Ensure nginx is installed
apt:
name: nginx
state: present
- name: Ensure nginx is running
service:
name: nginx
state: started
Idempotent tasks, not scripts
Notice the task reads "ensure nginx is installed," not "install nginx." Every built-in Ansible module is written to be idempotent: running this playbook against a server that already has nginx running changes nothing and reports "ok" rather than erroring or reinstalling. Run it against ten fresh servers and ten already-configured ones in the same batch, and every single one ends up in the exact same state.
Try it
ssh user@web1
When you're ready, hit Mark complete and move to the next lesson.
Challenge
Connect over SSH to web1 - the same way Ansible reaches every host in its inventory, just without installing anything on the other end first.
Want to experiment first? Try things in the practice terminal (opens in a new tab), then enter the command that solves the task here.
Quiz
Lock in the concepts. Score at least 80% to mark the lesson complete.
Done with this one?
Skipped the challenge? You can mark the lesson complete by hand.