Write your first YAML

vikas yadav
DevOps Dudes
Published in
2 min readMar 27, 2019

Overview of YAML

Photo by Kevin Ku from Pexels

YAML is an abbreviated form of “YAML Ain’t markup language”.

It is easy to understand data serialization language that works well with other programming languages for everyday tasks. It allows you to provide powerful configuration settings, without having to learn a more complex code type like PHP.

Here are some rules that you should follow when writing YAML code

  • YAML files should end in .yaml or .yml
  • YAML is case sensitive.
  • YAML uses spaces, NOT tabs, for indentation.

Now, let’s have a look at YAML elements

  • Scalars

These are often called variables in programming. If you want to specify some values such as an integer, string or a boolean you will use Scalars. For examples, if you are making a list of the type of animals, they would be the names given to those animals.

Most scalars are unquoted, but if you are typing a string that uses punctuation and other elements that can be confused with YAML syntax (dashes, colons, etc.) you may want to quote this data using single ' or double " quotation marks. Double quotation marks allow you to use escapes to represent ASCII and Unicode characters.

Integer: 10String: "10"Float: 10.0Boolean: yes
  • Sequences

A sequence places each item in the list at the same level. If you want to create a nested sequence with items and sub-items, you can do so by placing a single space before each dash in the sub-items. You can see an example of this below.

# Sequence- coke- Pepsi- Sprite# Nested sequence- hot drinks 
- tea
- coffe - milk

Sequences can be added to other data structure types, such as mappings or scalars.

  • Mappings

Mapping gives you the ability to list keys with values. This is useful in cases where you are assigning a name or a property to a specific element.

Drink: cold_drink

This example maps the value of pets to the animal key. When used in conjunction with a sequence, you can see that you are starting to build a list of pets. In the following example, the dash used to label each item counts as indentation, making the line items the child and the mapping line pets the parent.

Cold_drinks: - coke - Pepsi - Sprite

Hope that gives you an overview of YAML and its syntax. I also have a youtube video that explains YAML, please feel free to have a look at it.

I have a youtube channel where I upload high-quality IT-related content. Please feel free to have a look at my other free courses and subscribe to my channel.

Please feel free to check my other stories on medium

--

--

vikas yadav
DevOps Dudes

IT engineer with 14 years of experience in IT with recent experience in Solution design, Big data, and log analytics.