Introduction to YAML
A free video tutorial from Mumshad Mannambeth
Best Selling Instructor | Teaches Kubernetes
30 courses
1,460,262 students
Learn more from the full course
Ansible for the Absolute Beginner - Hands-On - DevOps
This course introduces Ansible to the absolute beginner in DevOps. Practice Ansible with coding exercises in browser.
02:14:37 of on-demand video • Updated August 2026
Beginner level introduction to Ansible
Introduction to YAML and Hands-on Exercises
Build Ansible Inventory Files with Hands-on Exercises
Build Ansible Inventory Files with Hands-on Exercises
Automate provisioning and web server deployment
English [CC]
Presenter: Now let's look at YAML. Every Ansible playbook is written in a format called YAML. It's a plain text file that represents data, in our case, configuration data like this short description of a server. If you've worked with XML or JSON before, you'll pick it up quickly. And the rest of the course depends on YAML, so it's worth learning well. YAML is just one of a few ways to represent the same data. Here's a quick comparison. On the left is XML, listing a server and its details. In the middle, the same data in JSON. And on the right, the same data in YAML. Take a minute to compare them. YAML is the cleanest and the easiest to read. Let's start with the simplest piece of data, a key value pair. You write the key, then a colon, then the value. Here the keys are fruit, vegetable, liquid, and meat, and the values are apple, carrot, water, and chicken. One rule to remember, you must put a space after the colon. Now let's look at an array or list. Say we want to list some fruits. We write fruits, a colon, and on each line below, we add an item with a dash in front. That dash marks each item as an element of the list. The vegetables follow the same pattern. How about a dictionary? A dictionary groups a set of properties under one item. Here we describe two fruits, banana and grapes, each with its own calories, fat, and carbs. Notice the spacing before each property. Every property under one item must line up with the same number of spaces. Spacing is where a lot of beginners trip up. On the left, banana's three properties share the same indentation, so calories, fat, and carbs all belong to banana. On the right, fat and carbs have extra spaces, so they fall under calories instead. But calories already has a value, so you can't add a map too. YAML throws the error: Mapping values are not allowed here. You can also nest these structures. Here's a list of fruits, banana and grape. But each element isn't just a name, it's a dictionary of its own, holding that fruits, calories, fat, and carbs. So this is a list of dictionaries. So when do you use each one? Think about a car. A car is a single object with properties: color, model, transmission, and price. To describe one object, you use a dictionary. And you can go deeper. If you want to split the model into a name and a year, you replace its value with another dictionary. That's a dictionary inside a dictionary. Now, say you want many cars, not just one. If you only need their names, a plain list of strings works, one name per line, each with a dash. But if you want every detail for each car, you swap each name for the full car dictionary. Now, it's a list of dictionaries, all your cars, fully described in one file. Two quick notes before the exercises. Dictionaries are unordered. These two describe the same banana even though fat and carbs are swapped because the values still match. Lists are ordered. These two are not the same because apple and banana sit in different spots. And one last thing, any line that starts with a hash is a comment and YAML ignores it. YAML is the language behind every playbook you'll write. Now let's head to the exercises and try it out.