C.W.K.
Stream
Lesson 08 of 08 · published

Linting & Validation — yamllint, schema, tooling

~10 min · yaml, linting, validation, yamllint

Level 0Plaintext
0 XP0/64 lessons0/12 achievements
0/100 XP to next level100 XP to go0% complete

The toolchain that catches YAML bugs before deploy

yamllint — style + correctness

yamllint is the standard YAML linter. It catches indentation drift, trailing whitespace, line length, syntax errors, mixed-quote styles, and common gotchas. Configure via .yamllint at repo root. Run in CI; fail the build on errors.

Schema validation — same JSON Schema, applied to YAML

YAML parses into the same data model as JSON, so JSON Schema validates YAML with no changes. Tools: check-jsonschema, ajv (with a YAML loader plugin), kubeconform (for Kubernetes specifically).

Tool-specific validators

  • kubeval / kubeconform — Kubernetes manifests against the official OpenAPI schemas.
  • actionlint — GitHub Actions workflow files. Catches typos in uses:, undefined env vars, missing checkout steps.
  • docker compose config — validates and normalizes compose.yaml, including anchor expansion.
  • helm lint — Helm chart YAML.
Principle: YAML is permissive at parse time and harsh at deploy time. The fix is shifting validation left — lint and schema-check in pre-commit, not in the cluster. The 30 seconds you spend setting up actionlint is the difference between a broken workflow caught locally and a broken main branch.

Code

yamllint quickstart·bash
# Install once
pip install yamllint
# or
brew install yamllint

# Lint a directory tree
yamllint .

# CI-friendly: exit non-zero on errors
yamllint --strict .

# Configure: .yamllint at repo root
cat > .yamllint <<EOF
rules:
  document-start: disable
  line-length:
    max: 120
  indentation:
    spaces: 2
EOF
Validate YAML against a JSON Schema·bash
# check-jsonschema (pip install check-jsonschema)
check-jsonschema --schemafile config.schema.json config.yaml

# ajv with js-yaml plugin (Node)
npm install -g ajv-cli
ajv validate -s config.schema.json -d config.yaml --data-stream

# kubeconform — for Kubernetes manifests
brew install kubeconform
kubeconform deployment.yaml service.yaml
actionlint — GitHub Actions linter·bash
# Install
brew install actionlint
# or
go install github.com/rhysd/actionlint/cmd/actionlint@latest

# Lint workflows
actionlint

# In CI:
actionlint -color

# Pre-commit hook (.pre-commit-config.yaml):
# - repo: https://github.com/rhysd/actionlint
#   rev: v1.6.27
#   hooks:
#     - id: actionlint

External links

Exercise

Pick one YAML-heavy directory in a project (.github/workflows, deploy/k8s/, ansible/). Run yamllint . and the appropriate tool-specific validator (actionlint, kubeconform). Fix every error. Add the lint command to a pre-commit hook or CI step. Future-you will thank you.

Progress

Progress is local-only — sign in to sync across devices.
Spotted a bug or have feedback on this page?Report an Issue

Comments 0

🔔 Reply notifications (sign in)
Sign inPlease sign in to comment.

No comments yet — be the first.