Capstone
Generating Remediation from Detected State
What you'll learn
- Deriving a remediation artifact from a real detection result, not a hardcoded assumption
- Why remediation is generated only for affected devices
- Why this stage stays deliberately small -- no templating engine needed
- How this feeds directly into the next lesson's Git evidence
Listen to a guided explanation of this lesson.
Spoken narration isn't supported in this browser.
From a detected gap to a generated fix
- Lesson 1's detection resultcompliant / non_compliant, from a real run
- generate_remediation()reads non_compliant, produces one line per affected device
- A remediation artifactno device touched yet -- this stage is pure data
The code
def generate_remediation(detection):
# One derived line per affected device -- nothing hand-typed, and
# nothing generated for a device detect_noncompliance() didn't flag.
return {entry["host"]: REQUIRED_NTP_LINE + "\n" for entry in detection["non_compliant"]}Real, verified code. Deliberately the smallest solution compatible with the existing stack -- no Jinja2, no templating engine. The remediation for this scenario is exactly one line, so a dict comprehension over the detection result is sufficient and honest about the scope.
Real, verified output
--- Remediation generated from Lesson 1's detection ---
{
'RTR1': 'ntp server 10.10.10.2\n',
'RTR2': 'ntp server 10.10.10.2\n',
'SW-EOS1': 'ntp server 10.10.10.2\n'
}Real, verified. Exactly the three devices Lesson 1 detected as non-compliant -- RTR1, RTR2, SW-EOS1 -- appear here. SW-JUNOS1, already compliant, is genuinely absent, not filtered out by a separate check.
What this stage does and doesn't do
No device touched yet
This stage is pure data transformation -- no napalm_configure, no connection, no device state changes anywhere in generate_remediation(). The remediation becomes real only once it's recorded as evidence (next lesson) and applied through the staged rollout (Lesson 4).
Key takeaways
- generate_remediation() takes Lesson 1's real detection result as input -- it does not assume or independently maintain a device list.
- Real, verified run: exactly the three non-compliant devices from Lesson 1 (RTR1, RTR2, SW-EOS1) receive generated remediation; the compliant device does not.
- Deliberately the smallest solution for this scenario -- a dict comprehension, not a new templating dependency.
- No device is touched at this stage -- this is data generation only, feeding the next lesson's Git evidence.
Done with this lesson?
Next lesson
Recording the Approved Change