The most detailed free FDE + DevOps library: 140+ lessons, 70+ labs and 80 long-form articles, in English and Turkish. Start learning →

DevOps Practitioner · Module 5: Ansible and configuration management · Lab

Apply Idempotent Service Config on Owned Lab Targets

50 min hands-on · Core

One or two learner-owned lab targets (local VMs or containers) plus a control machine; a static inventory containing only lab machines.

Local guide: run the steps below on your own machine in order, then check the validation list.

Objectives

  • Write a role that converges a service config from any starting state
  • Prove changed-then-ok across two consecutive runs
  • Roll back a bad change by reapplying the previous variables
  1. Step 1

    Write the converging role

    Write a role managing a service config file with templates and a handler restart. Review it with check mode and diff limited to one canary target before applying.

  2. Step 2

    Prove the second run is silent

    Apply to the group, then run again immediately and quote the all-ok output with zero changes. Any change on the second run is a task defect: fix the state test and repeat.

  3. Step 3

    Break and restore

    Apply a bad variable, watch the canary check catch it or the service complain, then restore by reapplying the previous variables and verify service health.

How to confirm it worked

  • Check-mode preview quoted before the first apply
  • Second run quoted all-ok with zero changes
  • Bad change restored via reapply with service verified
  • Inventory contains only learner-owned machines