Production Automation
Safe Rollback When a Stage Fails
What you'll learn
- rollback_stage(): a real, automatic response to a failed gate
- Why rollback() is the correct primitive here, not discard_config()
- Real, verified output from triggering rollback in this module's fail-path scenario
- That the decision to roll back is new; the rollback mechanism itself is not
Listen to a guided explanation of this lesson.
Spoken narration isn't supported in this browser.
The decision is new. The mechanism is not.
rollback() is unchanged from Phase 3.5
NAPALM's rollback() and discard_config() were both fully taught, with real signatures and real verified behavior, in NAPALM for Network Engineers (Phase 3.5). Nothing about either method changes here. What's new is the trigger: rollback happens automatically, as a direct, coded consequence of Lesson 3's gate returning FAIL -- not a manual runbook step a human decides to run later.
Why rollback(), not discard_config()
A real distinction, already taught, applied correctly here
NAPALM Lesson 5 drew a precise line: discard_config() abandons a candidate that was never committed; rollback() undoes a commit that already took effect. This module's stage always commits immediately, then validates the result (Lesson 3) -- so by the time a gate fails, the change is already live. rollback() is the correct choice for exactly that reason, not an arbitrary pick.
rollback_stage(): real, verified
from nornir_napalm.plugins.tasks import napalm_rollback
def rollback_stage(nr_subset):
return nr_subset.run(task=napalm_rollback)napalm_rollback is one of nornir_napalm's own real task functions (verified in Phase 3.6's own research) -- this module reuses it directly, not a hand-written connection call.
agg = rollback_stage(canary)
for hostname, mr in agg.items():
print(hostname, "failed:", mr.failed, "changed:", mr[0].changed, "result:", repr(mr[0].result))Run against the exact same canary host whose validation failed in Lesson 3 -- this is the direct next step, not a separate hypothetical example.
SW1 failed: False changed: True result: 'Rollback completed'Real, verified output. 'Rollback completed' is napalm_rollback's own literal, real return message -- not something authored for this lesson.
Connecting the gate to the rollback
gate = evaluate_gate(canary_result, threshold=1.0)
if gate["decision"] == "FAIL":
rollback_agg = rollback_stage(canary)
rolled_back = not rollback_agg.failedNo human decides to run this -- it's a direct if-branch on the gate's own decision, verified end to end in the capstone (Lesson 5).
Key takeaways
- rollback_stage() reuses nornir_napalm's real napalm_rollback task directly -- no new connection logic, no reimplementation.
- rollback() (not discard_config()) is the correct choice here specifically because this module's stages always commit before validating -- a direct, correct application of Phase 3.5's own real distinction.
- Real, verified output: 'Rollback completed' on the exact canary host whose validation failed in Lesson 3 -- the same scenario, continued, not a new hypothetical.
- The trigger is a direct if-branch on the gate's own decision -- rollback happens automatically on FAIL, and the rest of the fleet is never touched since expansion never runs.