defaults: &defaults
retries: 3
timeout: 30
api:
<<: *defaults
url: https://api.example.comAnchors reduce repetition and keep repeated config blocks synchronized.
Reusable YAML patterns using anchors and aliases, with merge examples and commands for expanding and validating resolved config.
Reuse repeated YAML fragments without copy-paste.
defaults: &defaults
retries: 3
timeout: 30
api:
<<: *defaults
url: https://api.example.comAnchors reduce repetition and keep repeated config blocks synchronized.
base: &base
image: node:20
pullPolicy: IfNotPresent
prod:
<<: *base
replicas: 3The merge key `<<` is widely used in tooling that supports YAML merge semantics.
common: &common
logging: json
security: &security
readOnlyRootFilesystem: true
service:
<<: [*common, *security]
port: 8080Useful for DRY configuration where shared defaults come from multiple sources.
yq 'explode(.)' config.yamlHelpful when you want to see the fully resolved YAML after merges and aliases.
Practical examples from CI, containers, and app config.
steps: &install_steps
- uses: actions/checkout@v4
- run: npm ci
jobs:
test:
steps: *install_steps
build:
steps: *install_stepsA common pattern in CI configs when repeated steps would otherwise drift apart.
env: &common_env
NODE_ENV: production
LOG_LEVEL: info
worker:
env: *common_envAnchors make shared environment sections easier to maintain.
yamllint config.yamlDuplicate keys can hide anchor or merge mistakes, so linting is especially useful in large files.