Introduction to YAML
Learn how to use YAML format for writing Ansible playbooks.
YAML and its structure
YAML (YAML Ain’t Markup Language) is a data serialization language. In Ansible, we use YAML for writing configuration files because it’s human friendly.
YAML files can either have a .yaml
or a .yml
file extension. The following code snippet shows two YAML files, config.yaml
and config.yml
:
config.yaml
config.yml
Components of a YAML file
When we write our configurations using YAML, the overall structure of our configuration is made up of the following major components:
- Document separator
- Key-value pairs
- Indentation
- Lists
- Dictionaries
- Comments
Document separator
YAML files typically start with three hyphens ---
. This is optional, but it’s a good practice to always include it in our configuration files. Here is a sample YAML configuration that shows how a YAML file starts:
# sample_file.yml---# configuration continues
Key-value pairs
In YAML, we use key-value pairs to define properties of elements. A key is typically followed by a colon (:
) and then the corresponding value. Whether the value needs to ...