DevOps · CI/CD

YAML Fundamentals

Pipelines, Docker Compose and Kubernetes are all configured in YAML. Small indentation mistakes break everything, so learn it properly.

Intermediate 5 min Lesson 12 of 30
0/30 in DevOps
On this page · 5 min · Intermediate

Learning objectives#

  • Write maps, lists and nested structures
  • Use multi-line strings
  • Avoid indentation and type pitfalls
  • Validate YAML

Explanation#

YAML uses key: value pairs. Indentation (spaces only, never tabs) shows nesting.

Lists use a dash per item, or inline [a, b].

Multi-line strings: | keeps line breaks (scripts), > folds them into spaces.

Watch types: yes/no and on/off can be read as booleans by some parsers; quote version numbers like "3.10" so they are not treated as numbers.

Code example: One file, all the basics#

YAMLOne file, all the basics Illustrative
app:
  name: shop-api
  replicas: 3
  version: "1.10"          # quoted: stays a string, not 1.1
  features:
    - search
    - payments
  env: { ASPNETCORE_ENVIRONMENT: Production, LOG_LEVEL: Information }
  startup_script: |
    dotnet ef database update
    dotnet Shop.Api.dll
  description: >
    This long text is folded
    into a single line.
Expected output
{ "app": { "name": "shop-api", "replicas": 3, "version": "1.10",
  "features": ["search", "payments"],
  "env": { "ASPNETCORE_ENVIRONMENT": "Production", "LOG_LEVEL": "Information" },
  "startup_script": "dotnet ef database update\ndotnet Shop.Api.dll\n",
  "description": "This long text is folded into a single line.\n" } }

This example is illustrative. Copy or download it and run it in your own environment; the expected output is shown above.

Step-by-step explanation#

  1. Two-space indentation nests keys under app.
  2. Dashes create a list.
  3. Inline braces create a map on one line.
  4. | keeps lines; > folds them.

Real-world use case#

Every GitHub Actions workflow, docker-compose.yml and Kubernetes manifest in this track.

Common mistakes#

Tabs or mixed indentation

YAML forbids tabs. Configure your editor to insert spaces.

Unquoted special values

Quote versions ("3.10"), times ("12:30") and values like "no" or "on".

Best practices#

  • Two spaces per level
  • Quote ambiguous values
  • Validate with yamllint or your editor
  • Keep files short; split when large

Remember this#

key: value, spaces only.

- item = list entry.

| keeps newlines, > folds them.

Practice exercise#

Your task: Write a YAML list of three regions: centralindia, southindia, westeurope.

Show solution
YAML Illustrative
regions:
  - centralindia
  - southindia
  - westeurope

Mini quiz#

YAML Fundamentals quizMultiple choice Question 1 of 1

Which character must never be used for YAML indentation?

Score so far: 0/0

Want more? Practise all DevOps MCQs · DevOps interview questions

My notes#

Saved in this browser.

Progress is saved in this browser. Sign in to sync.