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
- Tabs instead of spaces: YAML strictly prohibits tabs for indentation.
- Missing spaces after colon: Key-value pairs must have a space after the colon (
key: value). - Improper Boolean values: Some older parsers treat
yes/nooron/offas booleans, while newer ones treat them as strings. Always usetrue/false. - Indentation errors: Mismatched indentation is the most frequent cause of "Invalid YAML" errors.
Example: Indentation Error
services:
web:
image: nginxThe 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 6Use a linter like yamllint or yq to catch these errors.