Pcornel
Automation · Templates

Conditions

Cheat sheet · https://pcornel.dk/topic.php?topic=5809

Back to the Topic

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

LayerTemplates → Conditions operational reference
Context identityJinja 3.1/current + exact revision/input/target identity
Persistent intentVersioned contract/configuration with explicit ownership and prerequisites
VerificationValidate inputs/read current state → exercise bounded operation → independent target read-back
Output contractPreserve structured status/IDs/properties before human formatting
Failure boundarySeparate 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

Confirmation

Confirm action

Continue?