- Keys and values are separated by a colon followed by a space:
key: value. - YAML uses indentation (spaces) to denote structure; there are no braces or closing tags.
- Use consistent indentation throughout a file (commonly 2 spaces but 4 is also used in many projects).
- Prefer quoted strings when values could be interpreted as other types (e.g., dates or numeric-like strings).
- Each item is prefixed with a dash and a space (
-).
- A mapping groups related key-value pairs under a single name.
- All properties that belong to the same mapping must be indented consistently. Incorrect indentation changes the structure or causes a parse error.
- Correct mapping example (Banana with properties):
Fat and Carbs are indented more than Calories, which makes them nested under Calories (a scalar), and YAML will error:

- YAML supports arbitrary nesting. You can create sequences of mappings, mappings whose values are sequences, or deeper nested combinations.
- Use a mapping (dictionary) to represent a single object with named properties (for example, one car with attributes).
- Use a sequence (list) to represent multiple items of the same kind (for example, a list of cars).
- When each item in the list has multiple properties, use a list of mappings (each list element is a mapping/dictionary).
Key notes
- Mappings (dictionaries) are unordered collections: the order of keys inside a mapping does not matter. These two mappings are equivalent:
- Sequences (lists) are ordered collections: the order of items matters. The two lists below are different:
- Comments start with
#and are ignored by the parser:
YAML syntax is simple but indentation-sensitive. Use a consistent number of spaces (commonly 2) for each level of indentation. When in doubt, quote values that look like dates, numbers, or contain special characters to avoid type coercion.
- YAML specification: https://yaml.org/spec/
- YAML tutorial: https://www.yaml-tutorial.com/
- Ansible playbook basics: https://docs.ansible.com/ansible/latest/user_guide/playbooks.html