unit 7 · Secrets & scale

Run control: check, diff, tags, limit

The pre-prod ritual

essential · 7 min · linux + windows

you may want to read 12 · Playbook anatomy first — but nothing is locked

tl;dr

  • --check dry-runs the playbook: modules report what would change without changing anything.
  • --diff adds line-by-line file diffs; tags: plus --tags runs a named slice of the tasks.
  • The pre-prod ritual: --syntax-check, --list-tasks, --check --diff, then the real run.

why it matters The first time you point a playbook at machines people depend on, --check --diff is the difference between confirming your intent and discovering it live.

Every flag here answers the same nervous question: what exactly will this playbook do when I hit enter? Since lesson 12 you’ve run ansible-playbook bare — fine against a lab VM. Against machines people depend on, you run a ritual first. Every step is a flag on the same command.

Check mode: the dry run

--check puts the whole run into check mode : every module reports what it would do — changed or ok per task — without touching the host. Every module already compares desired state against current state before acting; check mode stops after the comparison and reports the verdict.

Add --diff and file-shaping modules like template and lineinfile print the line-by-line diff of what would change. Learn the two flags as one word: --check --diff means “show me the edit before you make it.”

Tags: run a slice

Any task or play can carry tags:. They do nothing until you ask for them:

- name: Renew the TLS certificate
  ansible.builtin.command: certbot renew # command task — skipped under --check
  tags: [certs]

- name: Push the nginx config
  ansible.builtin.template: # file-shaping task — previews under --diff
    src: nginx.conf.j2
    dest: /etc/nginx/nginx.conf
  tags: [nginx]
tag tasks now, slice the run later

--tags certs runs only the tasks tagged certs — everything untagged is skipped for that run. --skip-tags is the inverse: run everything except. That’s how a 40-task playbook re-runs just its certificate steps.

Narrowing and resuming

Tags slice tasks; --limit (lesson 10) slices hosts — the same flag as on ad-hoc commands. When a run dies at task 31 of 40, --start-at-task resumes from a named task instead of replaying the 30 that already converged:

ansible-playbook site.yml --tags certs --limit web01 # just certs, one host
ansible-playbook site.yml --skip-tags nginx # everything except nginx tasks
ansible-playbook site.yml --start-at-task 'Push the nginx config' # resume
slicing and resuming the same playbook

Seeing more: the verbosity ladder

When a run confuses you, the same command takes -v flags. -v prints each task’s full result dict — what register: would have captured. -vvv adds connection detail and the exact arguments each module received. That settles lesson 16’s question of which value won precedence: you see the value Ansible actually used. -vvvv turns on connection debugging — SSH’s own debug output — for “why can’t it even reach the host” problems. Start at -v; escalate only when needed.

The ritual

Before a playbook touches anything real, four commands in order:

ansible-playbook site.yml --syntax-check # parse errors; nothing runs
ansible-playbook site.yml --list-tasks # the run plan: task names + tags
ansible-playbook site.yml --check --diff # what would change, shown as diffs
ansible-playbook site.yml # the real run
the pre-prod ritual — three rehearsals, then the run

You met --syntax-check in lesson 13 — it catches YAML and playbook-structure errors without contacting a single host. --list-tasks also runs nothing. It prints every task name with its tags: your preview, and the fastest way to find the exact string --start-at-task and --tags want.

The flags compose into sentences: --limit web --tags nginx --check --diff reads as “show me what the nginx tasks would change on the web hosts.” When a colleague says run it in check mode first, they mean this ritual, not just the one flag.

replay — Preview with --check --diff, then the real run

a recording, not a simulator — tap ⓘ lines for what they mean

at work, this sounds like

“Run it in check mode first.”
Do a --check dry run and read what would change before anything actually does.
“Crank it up to -vvv and rerun.”
Raise verbosity to see connection detail and the actual values Ansible used for each task.

self-check — recall, not a test

  1. 1 Why do command and shell tasks skip under --check, and what does that mean for trusting a clean dry run?

  2. 2 You need to re-run only the certificate tasks of a 40-task playbook, on one host. Which flags?

  3. 3 Recite the pre-prod ritual in order, and what each step catches.

lab (optional — never required)

Write a two-task playbook against localhost, tag one task, then run the full ritual: --syntax-check, --list-tasks, --check --diff, --tags, real run.

needs: The control node from lesson 5.

next up 30 · Windows connections: WinRM, PSRP, SSH 7 min · unit 8