YAML is a human-friendly data serialization standard for all programming languages. It is commonly used for configuration files but could be used in many applications where data is being stored or transmitted.
The syntax of a yml file
“.yml” files can be recognized by the 3 lines “ — -“ at the beginning of the file and 3 dots “…” at the end of the file.
The meanings of some of the most used characters:
- “ ” Blank space indentation is used to denote structure
- “-” is used to denote list members. Each member has to be on a new line.
- “” is another way to denote list members in a single line, separated by a comma “,”
- “: ” by using the colon and space, associative arrays are represented.
Example of yml file:
YAML & Ansible
YAML has different uses but one of the best uses it with Ansible.
Ansible uses .yml files for the specific playbooks. For Ansible, nearly every YAML file starts with a list. Each item in the list is a list of key/value pairs, commonly called a “hash” or a “dictionary”. All members of a list are lines beginning at the same indentation level.
Example of a simple list:
A dictionary is represented in a simple “key: value” form.
Example of a dictionary:
You can mix those two shown before and get lists of dictionaries. Possibilities are endless.
Example of lists of dictionaries: