Pcornel
Automation · Templates

Loops

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

Back to the Topic

Answer

Loops in templates repeat a block for each item, such as {% for intf in interfaces %} to generate interface sections, keeping templates short for many items.

Remember

  • {% for %} repeats blocks.
  • loop.index and loop.last help formatting.
  • Handle empty lists.

First checks

  • {% for vlan in vlans %}…{% endfor %} — loop
  • loop.index / loop.last usage — formatting
  • Empty list handling ({% else %}) — edge cases

Verify in this order

list → loop → repeated blocks

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.

Read-only verification commands unless stated otherwise. Confirm syntax for your platform and release. Full reference: https://pcornel.dk/topic.php?topic=5810

Confirmation

Confirm action

Continue?