Configuring complex environments
At the Controls
The DevOps world without YAML [1] is difficult to imagine. In fact, YAML is a superset of JavaScript Object Notation (JSON) [2]. However, the focus of JSON is more on data serialization (e.g., to make data available to an API).
In contrast, YAML plays to its strengths when used as a configuration language because the format is more easily readable than JSON. Python programmers love YAML because, unlike JSON, it uses indentations instead of parentheses to define objects.
Basic YAML Syntax
Listing 1 shows a simple YAML document. The ---
string in the first line means a file can contain several such documents; it is then followed by typical key-value pairs, which are familiar if you have used JSON. The first key pair is a simple scalar with a string value, although numbers and booleans are also allowed. The list that follows is a collection of objects. In this case, only numeric values are used, each of which is indented with spaces.
Listing 1
YAML Objects
--- name: starwars collection year of publication: - 1977 - 1980 - 1983 movies: # Only movies from the original trilogy (OT) are listed here. ot: - Episode IV - A New Hope - Episode V - The Empire Strikes Back - "Episode VI - Return of the Jedi Knights."
You should avoid using tabs if possible because they can cause issues when processing the data. By the way, you do not have to write strings in parentheses, as shown in the final line of Listing 1. This collection of key-value pairs is a
...Buy this article as PDF
(incl. VAT)