← Lessons/Your First Playbook

Your first playbook

You've automated tasks with Bash scripts: a list of steps, "do this, then this". Ansible flips that around: you describe the end state you want, and Ansible works out what to do to get there. It's the same shift Terraform makes for cloud infrastructure; Ansible is its sibling for configuring machines (packages, config files, services).

You write your playbook in the editor and press Run: it executes as ansible-playbook playbook.yml against this sandbox.

ansibleconfiguration-managementautomation

Interview prep

The declarative vs. imperative distinction is the first thing an interviewer probes about Ansible.

How is an Ansible playbook different from a Bash script that does the same thing?

A Bash script is imperative — a list of commands that run every time, whether or not they're needed. A playbook is declarative: each task describes a desired state, and Ansible only acts when reality doesn't match. That makes it idempotent (safe to re-run) and is why it's the standard for configuration management instead of a pile of shell scripts.