Automation · Data Formats › YAML
Anchors
Cheat sheet · https://pcornel.dk/topic.php?topic=5828
Answer
YAML anchors (&name) and aliases (*name) reuse a block elsewhere in the same file, and merge keys (<<: *name) combine it with extra fields, reducing repetition in CI and Compose files.
Remember
- &anchor defines a block; *alias reuses it.
- <<: *alias merges a mapping.
- Anchors only work within one file.
First checks
yq 'explode(.)' file.yaml— expand anchors/aliases- Anchor (&) and alias (*) usage — reuse
- Merge keys (<<) — support varies
Verify in this order
&anchor → *alias → reused content
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.
YAML → Anchors · operational reference
| Layer | YAML → Anchors operational reference |
|---|---|
| Runtime/ownership | YAML 1.2.2 anchors and aliases · identify controller/parser, durable intent, identity and target ownership before mutation |
| Persistent intent | Versioned definition/configuration with explicit dependencies, scope and credential boundary |
| Verification | Parse a fixture containing &anchor and *alias with the actual automation parser, inspect the resulting native structure, then round-trip or schema-validate where supported. |
| Expected interpretation | Aliases resolve to the intended previously anchored node, merge/application semantics are parser-compatible, and the automation does not rely on anchor names as durable business data. |
| Recovery boundary | Preserve correlation IDs + pre-state, repair first failing boundary, then verify the target independently |
Read-only verification commands unless stated otherwise. Confirm syntax for your platform and release. Full reference: https://pcornel.dk/topic.php?topic=5828