YAML & YML files

Alex Marginean
2 min readNov 23, 2018

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.

YAML uses both Python-style indentation to indicate nesting and a more compact format that uses “[ ]” for lists and “{ }” for maps making YAML 1.2 a superset of JSON.

The syntax of a yml file

YAML accepts the Unicode character set. The YAML document may be encoded in UTF-8, UTF-16, and UTF-32.

“.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.
  • etc..

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:

--

--

Alex Marginean

I’m a Romanian🇷🇴 Computer Science student who likes programming and design. Here you can read about either my life experiences or different tutorials.