Automation
Ansible: qualify check mode before a production change
A runbook for exposing Ansible simulation blind spots, protecting sensitive output and choosing a canary or rollback.
An Ansible check-mode job finishes without errors ahead of a configuration change. It is tempting to treat that green result as proof that deployment will be uneventful. But a skipped task, an incomplete simulated result or a task forced to run normally can make that conclusion unsafe.
In this fictional case, a playbook deploys a service configuration across several servers, validates its syntax and triggers a restart when the file changes. The goal is to establish what the simulation actually covers before changing a single production server.
Freeze the execution contract and protect evidence
Record the Git revision actually used, Ansible and collection versions, execution environment, resolved inventory, target hosts, variables and identities. In AWX, retain the job ID, template, project, inventory, limit and events. Compare these with the intended live run: a changed dynamic inventory or variable can invalidate the simulation.
Store output in the approved restricted incident location. Diff output can disclose secrets or business data, so review it before enabling it broadly. Use diff: false for sensitive tasks and handle logs appropriately. Masked output protects content, but is not evidence of the proposed change.
Map what check mode cannot prove
Review tasks and their modules, including roles and handlers. Support for check and diff depends on the module and version in use. Searching for check_mode: false helps find tasks forced to run normally, but does not replace review of includes, roles, delegation, plugins and external calls.
| Observation | Risk | Evidence needed before a decision |
|---|---|---|
| Module does not support check mode | Task is skipped and its live effect is unknown | Read the documentation for the installed version and test in isolation |
check_mode: false | A task can change a target during the simulation | Identify its effects and remove or isolate the override before testing |
| Command or script | An arbitrary command cannot necessarily predict its effect | Inspect the code, external access and any creates or removes conditions |
| Registered result used downstream | A branch may be skipped or incompletely simulated | Compare evaluated paths with a disposable-system test |
| File reported changed | A diff proves neither valid syntax nor a healthy restart | Validate the rendered file and service behavior |
The ansible.builtin.command module has partial check-mode support: creates and removes provide a prediction based on file existence, not a general simulation of a script. A task forced into normal mode can also act on a delegated system or API. Until those effects are bounded, do not run the simulation against production.
Build evidence on a disposable target
Use an isolated, representative target with no production credentials or data and no access to live systems. Keep the same revision and an equivalent variable contract, explicitly substituting external destinations. Record differences that limit representativeness.
After reviewing tasks and data that diff could expose, run the simulation on that target:
ansible-playbook -i inventory-test.yml service.yml \
--check --diff --limit canary-test.example
Keep the recap and skipped tasks, then compare the prediction with a real run on the same disposable target. Check the rendered file, syntax validation, restart, service state and a functional transaction. Run the real playbook again to examine idempotency and repeated effects; a second unchanged run alone does not prove that every external side effect is absent.
For each discrepancy, record the task, host, expected effect, observed result and missing coverage. Fix the playbook or define an additional check. Do not silently count a skipped task as a success.
Authorize a production canary
Before writing, obtain the owner’s approval and choose a representative host that can be taken out of traffic. Back up the configuration and identify its baseline version, dependencies, health checks, owner, observation window and stop threshold. Verify that restoration and return to service are feasible; a file copy may not cover an external state change.
Immediately before launch, compare revision, variables, inventory, identity and target state with the evidence. Stop and requalify if the context has drifted. Apply the real change to the canary only, then inspect service health, logs, metrics and a representative transaction. Check dependencies and other hosts before expanding gradually.
Decide or roll back
- Promote when blind spots are covered, the canary matches the approved change and checks remain healthy throughout the agreed window.
- Hold when an unevaluated task, external effect or inventory discrepancy remains unexplained.
- Roll back if the canary degrades service: stop expansion, restore the known version on changed targets and validate the service and its dependencies. Address irreversible external effects, or effects outside that restoration, separately.
A green check-mode result is useful evidence, not production authorization. The decision depends on task coverage, a bounded real execution and a verified recovery path.