Javatpoint Logo
Javatpoint Logo

Ansible YAML

YAML is used to describe configuration that has been increasing in the past few years with the help of Ansible and SaltStack.

YAML is more comfortable for humans to read and write in comparison to other standard data formats such as XML or JSON. There are libraries available in most programming languages for working with YAML.

For Ansible, every YAML file starts with a list. Each item in the list is a list of key-value pairs, commonly called a "hash" or "dictionary". So, we need to know how to write lists and dictionaries in YAML.

There’s another small quirk to YAML. All YAML files (regardless of their association with Ansible or not) can optionally begin with --- and end with ---. This is part of the YAML format and indicates the start and end of a document.

All members of a list are lines beginning at the same indentation level starting with a "-" (a dash and space):

We have different ways in which the YAML data is represented, such as:

Key-value Pair

YAML uses the Key-Value pair to represent the data. And the dictionary is described in the key: value pair.

NOTE: There should be space between: and value.

For example, a student record

Abbreviation

We can also use the abbreviation to represent the directories:

Representing List

We can also represent List in YAML. Every element (member) of the list should be written in a new line with the same indentation starting with "-" (- and space).

For example: Name of the countries

Abbreviation

To represent the list, we can also use the abbreviation method:

List inside Dictionaries

We can use the list inside dictionaries, i.e., the value of a key is a list.

For example, a student record

List of Directories

We can also make a list of directories:

For example:

YAML uses "|" to include newlines while showing multiple lines and ">" to suppress newlines while showing various lines. Due to this, we can read and edit long lines. In both cases, the indentation will be ignored.

We can also represent Boolean (True/false) values in YAML, where Boolean values can be case insensitive.

For example, a student result


Next TopicAnsible Inventory




Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA