G
GuideDevOps
Lesson 7 of 9

Common YAML Pitfalls

Part of the YAML tutorial series.

Overview

YAML's flexibility is often its downfall. Small formatting mistakes can lead to complex bugs in your automation scripts or infrastructure manifests.

Common Mistakes

  1. Tabs instead of spaces: YAML strictly prohibits tabs for indentation.
  2. Missing spaces after colon: Key-value pairs must have a space after the colon (key: value).
  3. Improper Boolean values: Some older parsers treat yes/no or on/off as booleans, while newer ones treat them as strings. Always use true/false.
  4. Indentation errors: Mismatched indentation is the most frequent cause of "Invalid YAML" errors.

Example: Indentation Error

services:
  web:
  image: nginx

The image key is at the same indentation level as web, which might be invalid depending on the expected structure.

Result: Most linters will flag this immediately.

Error: mapping values are not allowed in this context at line 3, column 6

Use a linter like yamllint or yq to catch these errors.