Photo by Austin Neill on Unsplash

Photo by Austin Neill on Unsplash

Configuring complex environments

At the Controls

Article from ADMIN 68/2022
YAML is often the language of choice when configuring complex environments. We help you get started with YAML and the YAML parser yq.

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
# Only movies from the original trilogy (OT) are listed here.
       - 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

Use Express-Checkout link below to read the full article (PDF).

Buy this article as PDF

Express-Checkout as PDF
Price $2.95
(incl. VAT)

Buy ADMIN Magazine

Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content

comments powered by Disqus