Use this when writing YAML lists for playbooks, manifests and CI pipelines.
Sequences
YAML sequences are lists, written with a dash per item or inline as [a, b]. They correspond to JSON arrays, such as a list of hosts or tasks.
1. Sequences are lists (- item).
2. Consistent style.
3. Nested lists need careful indentation.
4. Empty list: [].
5. Validate element types.
- item → sequence
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 encoding/BOM issues, delimiter/quoting ambiguity, duplicate keys, namespace drift, scalar coercion, invalid schema assumptions and parser success without consumer-valid semantics, choosing the cases most relevant to ordered list semantics, item typing, nested structures and preserving order/index identity when mapping YAML to consumer objects.
Step 2 Common mistakes Narrow the fault
- Mixing list and mapping at the same indentation level.
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.
- Sequences are lists with a dash per item.
- Inline form [a, b] also works.
- Indentation must be consistent.
yq '.items | length' file.yaml— sequence lengthyq '.items[0]' file.yaml— element- Block (-) vs flow ([ ]) style — readability
ReferenceWhy it matters1 section · depth on demand
In depth
A YAML sequence is an ordered list, written with a dash per item or inline with brackets. Items can be scalars or mappings.
ntp_servers:
- 10.0.0.123
- 10.0.0.124
vlans: [10, 20, 30]
interfaces:
- name: Gi1/0/1
vlan: 20
- name: Gi1/0/2
vlan: 30
A frequent mistake is indentation that turns a list item's keys into a separate mapping, or a missing dash that merges two items. When in doubt, convert to JSON to see the actual structure: python3 -c 'import yaml,json,sys; print(json.dumps(yaml.safe_load(sys.stdin), indent=2))' < file.yml.
ReferenceImportant terms & boundaries1 section · depth on demand
Mechanics
The linked authority for bounded mechanics is YAML 1.2.2 Specification; documentation support is separate from observed lab/production Evidence.
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 YAML > Sequences. Documentation verification only; this is not observed lab or production Evidence.
Basis: https://yaml.org/spec/1.2.2/ · confidence 94%Deep reference
Healthy vs suspicious evidence
Output interpretation
For ordered list semantics, item typing, nested structures and preserving order/index identity when mapping YAML to consumer objects, prefer typed fields and stable IDs over human presentation text.