Automation · Templates
Conditions
Cheat sheet · https://pcornel.dk/topic.php?topic=5809
Answer
Conditions in templates include or change output based on variables, such as {% if vlan_id %} ... {% endif %} in Jinja2, so one template covers several cases.
Remember
- {% if %} includes parts conditionally.
- Test every branch.
- Keep logic simple.
First checks
{% if enable_ssh %}…{% endif %}— condition example- Test both branches — coverage
- Avoid deep nesting — readability
Verify in this order
condition → included block
Where it usually breaks
Input/desired state → request accepted → job/task terminal status → target object read-back → effective runtime state → original workload → regression/rollback readiness.
Templates → Conditions · operational reference
| Layer | Templates → Conditions operational reference |
|---|---|
| Context identity | Jinja 3.1/current + exact revision/input/target identity |
| Persistent intent | Versioned contract/configuration with explicit ownership and prerequisites |
| Verification | Validate inputs/read current state → exercise bounded operation → independent target read-back |
| Output contract | Preserve structured status/IDs/properties before human formatting |
| Failure boundary | Separate source/input/engine/controller execution from downstream target outcome |
Read-only verification commands unless stated otherwise. Confirm syntax for your platform and release. Full reference: https://pcornel.dk/topic.php?topic=5809