November 14th, 2018
DevOps Training Architect I in Content
YAML Essentials gives even the absolute YAML beginner the skills they need to craft documents using this popular data serialization language. Used across a variety of programs and languages for a vast array of reasons, YAML is a popular choice for data storage, configuration files, configurations management, and more. This course explores how to write a properly structured YAML file in both the human-readable block style and the JSON-compatible flow style.
About the Course
Are you ready to learn some YAML? In this introductory video, we'll cover what this course is about and how we'll be breaking down YAML as we learn.
About the Training Architect
Meet the training architect teaching this course in this short video!
What is YAML?
In What Is YAML?, we'll discuss the most basic of YAML question – is YAML (yet) another markup language? What is it commonly used for? Where did it come from? We'll also discuss why YAML is great for humans and the seven core goals of YAML.
Have you ever wondered where YAML stood in the tabs versus spaces debate? In this lesson, we'll take a look at the most basic syntax conventions that make up a YAML document and learn how to parse a YAML document even if we aren't sure how to write one yet. Finally, we'll take a look at the character encodings that YAML supports and how to ensure our YAML is compatible with JSON.
You're probably familiar with the block-style YAML that often resembles a clean, human-readable list. But did you know YAML can also work as an extension of JSON? YAML offers both "block" and "flow" styles for those who want a more easy-to-read YAML file as well as those who want to be more computer-friendly, JSON-style setup.
Mappings are also known as hash maps or associative arrays and allow us to assign a value to a key that we also define. Mappings are one of the key elements of YAML, and we can tell something is a map by it's key: value structure – note the colon-space combination that marks it as a mapping. We also take a look at how to use flow style mappings.
Sequences are also known as arrays and lists, and allow us to provide an inventory of data using a dash-and-space combination that marks it a sequence. Sequences can also be combined with mappings to create "sequences of mappings," "mappings of sequences," and even "mappings of mappings" and "sequences and sequences." In this lesson, we take a look at how to create a sequence in both block and flow styles, as well as review some common mistakes when writing them.
Now that we know how sequences and mappings work, we can take a look at how we add data to them by learning about scalars – the individual bits that make up a key or value, as well as some basic tricks to manipulate these values both on the processing end and for the sake of human viewability.
We now have a basic YAML file! But did you know YAML can contain more than one directive (or document) in a single file? In this lesson, we'll take a look at the triple-dash structure that signals the beginning of a directive, as well as the triple-dot ending signal we can include at the end.
Those familiar with other languages are probably wondering where the comments are right about now – but don't worry, that's what this lesson is for! We'll learn that YAML works like a lot of other languages, using the octothorpe for comments, and how to add inline and on-line comments. We'll also go through some common commenting mistakes.
Tags provide us with three functions: The ability to assign a universal resource indicator, the ability to assign local tags to that indicator, and the ability to change how the YAML parser reads certain scalars when processing the YAML itself. We first take a look at how to assign a URI using the %TAG header, then we assign some local tags with !, before finally learning how to use the !! indicator to change the data type of a scalar. Default data types: seq - Sequencemap - Mapstr - Stringint - Integerfloat - Floating-point decimalnull - Nullbinary - Binary codeomap - Ordered mapset - Unordered set
Anchors allow us to reuse data across a YAML file. Have a list or scalar that needs to be referenced again and again? With an anchor, we can use the & prefix to assign some data a name, then use the * with that name to call it repeatedly throughout the file, making updating large files a quick and easy process.
Final Thoughts and Next Steps
Congratulations on completing YAML Essentials! Now that your YAML skills are up to par, why not check out one of our many courses where you can try them out?