Use this when validating rendered templates.
Validation · Templates
Validation of rendered templates checks the output before deployment, such as nginx -t, a YAML lint, a device config parser or comparing with the golden configuration.
1. Validate rendered output: syntax (native tools), schema, semantics.
2. Run in CI before deploy.
3. Fail fast.
4. Test edge cases.
5. Keep validation close to the target platform.
rendered config → validators → pass/fail
Context & applicabilityCommon mistakes · platform/version boundaries
Operational reference
Fast context before you go deeper.
Verification & Troubleshooting
Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.
Use the operational verification above to establish the expected state.
Capture the concrete output, symptom, packet, log or counter before changing anything.
Step 1 Verification path Verify boundary
The negative fixture should deliberately exercise risks such as undefined values, unsafe escaping, implicit type conversion, environment-specific filters, secret exposure, whitespace-sensitive syntax and valid render producing invalid target configuration, choosing the cases most relevant to schema and semantic validation before execution, actionable errors with field/path identity and revalidation after defaults/transforms are applied.
Step 2 Common mistakes Narrow the fault
- Validating only the template, not the rendered result.
Evidence · 1 on this Topic
Expected observations and documentation recipes are reference material. Record actual output, device identity, scope and time before claiming a verified result.
- Validate with the target's own checker.
- Lint rendered output.
- Compare with golden config.
nginx -t -c out.conf / sshd -t -f out.conf— syntax validationyamllint out.yaml— structural lint- Batfish/pyATS for network configs — semantic validation
ReferenceWhy it matters1 section · depth on demand
What it is
Template validation checks rendered output: syntax (yamllint, device parsers), schema and policy tests.
ReferenceImportant terms & boundaries1 section · depth on demand
In depth
Template validation checks both the template and its output: does the template render without errors for every data set, and is the output valid for its target system? A template that renders fine can still produce configuration the device rejects.
| Check | Tool |
|---|---|
| Undefined variables | StrictUndefined, ansible --check |
| Syntax of output | yamllint, jq, nginx -t, named-checkconf |
| Network config semantics | Batfish, device dry-run (configure replace … list), Containerlab test |
| Policy | Required lines present, forbidden lines absent |
rendered = template.render(**data)
assert "no ip http server" in rendered
assert "snmp-server community public" not in rendered
Additional reference context Scope · expected state · examples · history · terminology Open only when you need the supporting context
Verification history & basis
When and against what this Topic was checked. Later text edits do not count as a new check.
Authoritative/upstream documentation reviewed for bounded claims in Templates > Validation. Documentation verification only; this is not observed lab or production Evidence.
Basis: https://jinja.palletsprojects.com/en/stable/templates/ · confidence 94%