Configuration validation and rollback
Quick answer
Validate a candidate before replacing active configuration, then verify behavior. Retain the previous known-good configuration and a recovery path.
Syntax acceptance and operational acceptance are separate gates. A valid configuration may still target the wrong endpoint. Validate a candidate in isolation, check a representative request after activation, and define the rollback trigger before changing state.
Prepare the practice environment
Run python3 lab-fixtures/automation/setup.py from the extracted root as an ordinary user. Enter the printed fresh private path and check pwd. Use fresh fixtures, Bash with set -e -o pipefail, LC_ALL=C and umask 077. Run each snippet in a separate Bash process, not your interactive shell. Only private files are used; optional examples require an authorized snapshot VM. Do not modify system services. Review the lab guide.
Prerequisites
Review: Templates and secrets.
How it works
Preview differences without exposing secrets. A syntax check verifies structure, while semantic checks enforce required fields and allowed ranges. Runtime readiness is a separate check. Stage the candidate on the same filesystem and atomically replace a private file only after validation; atomic replacement alone is not crash durability or a full transaction. If a simulated health check fails, restore the original bytes and mode, then verify again. Real reloads require approved service-specific commands, concurrency control, backup, tested access and recovery. The supplied helper models this workflow for a JSON configuration, not actual Nginx or systemd behavior.
Try the examples
diff -u --label active --label candidate active.json candidate.json || test "$?" -eq 1diff returns 1 for differences; other nonzero results should not be treated as a normal difference. These files contain dummy settings only.
Expected stdout:
--- active+++ candidate@@ -1 +1 @@-{"port": 8080, "ready": true}+{"port": 8081, "ready": true}An out-of-range port is rejected before changing the active scratch file.
Expected stdout:
invalid candidate rejectedoriginal preservedThe candidate is syntactically and semantically valid but its modeled readiness is false. The helper restores the previous bytes and permission mode.
Expected stdout:
candidate validhealth failedoriginal restored and verifiedCommon mistakes
Never reload a service merely because a file was written. Do not treat syntax success or an atomic rename as a full service recovery guarantee.
Practice
Run invalid and rollback. Describe which checks occur before and after the change and how you would verify a real service through an authorized VM console.
Related references
Study: nginx, systemctl. These are reference names, not deployed links.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Configuration validation and rollback — Knowledge Check
Apply configuration management concepts to synthetic fixtures and VM-only scenarios.
When should a candidate be validated?
What does diff exit 1 normally mean?
Can valid syntax guarantee readiness?
What follows failed readiness?