YAML 101 : A brief introduction

Yaml is a easily readable language for writing configuration files that store data  used by different applications, like kubernetes and docker.

Yaml uses indentation to structure its data, it is also case-sensitive.

Yaml files can have the .yaml or .yml extension.

Yaml uses variables and objects. Objects serve as "containers" for the variables or other objects.

Data in YAML files:

Data in a Yaml file has the below format:

Data types by example:

Key/value examples:

We can gather all that information in an object and call it"automobile":

Access to the color variable could be done through: "automobile.color" for example.

If we have multiple automobiles, we can put them in a list:

The pink line that starts with a "#" is a comment, it is not taken into account by Yaml.

Sold variable is a boolean variable that could have the "true" or the "false" value.

We can also have a list including just the brands of the cars:


An example of a list would be the "available_colors" below, it contains the "white","black" and "green" elements:

Another way to write the available_colors list is as below:

Mapping keys to values:


We could see above, two ways of defining lists members in the employee object.

Nested objects:

"Owner" is a nested object inside the "automobile" object.

Accessing environmental variable:

We use the "$" sign to access environmental variables:

Here we have a list of commands, install_path and lib_path are environmental variables accessed through the "$" sign.

Line manipulation:

When we write a variable "paragraph" as a multi-line text (for visibility reason) and we want Yaml to interpret it as a line , we use the ">" sign:

If we want to preserve the formatting of our variable "paragraph" and keep it as we wrote , we use the "|" sign:

Type casting:

If we want Yaml to interpret a variable as a "float" or as a "string" we use the below:

Number is interpreted as a float 1.0

String is interpreted as a string "23"


Leave as a comment: