Appendix B. YAML

YAML stands for YAML Ain’t Markup Language. (It used to be something else, but was changed to focus more on its data-oriented nature.) YAML is used heavily throughout Salt; from state files (SLS) to all of the configuration files, you will find YAML in many places. We have assumed that you have some basic familiarity with YAML and can thus follow along with the simple use cases in this book.

In order to better visualize the following example, we will use an online YAML parser. You can enter YAML in one text box and see a JSON representation next to it.

However, as with any language, YAML does have some quirks. Just like Python, YAML uses indentation for scoping, but you have to use spaces and not tabs. If you are having difficulty with states not compiling properly or with configuration files not being read as you expect, first make sure you do not have your editor set to replace spaces with tabs.

The next thing you should know is that YAML uses a leading hash (#) as an indicator for a comment. This is just like many scripting languages. For example, bash, Perl, and Python all use the hash for comments.

YAML has data structures for strings, integers, lists (arrays), and dictionaries. There are even shorthand ways of creating some of them. The data structures are formed using simple a key: value format.

While strings may be simple enough to understand, multiline strings have a couple of options. If you add a greater than sign (>), the end-of-line characters are ...

Get Salt Essentials now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.