Introduction to Ansible Transcripts
Chapter: Ansible Core Concepts
Lecture: YAML
Login or
purchase this course
to watch this video and the rest of the course contents.
0:00
YAML is a recursive acronym that stands for YAML Ain't Markup Language. That's probably just going to be trivia for you
0:07
hardly anyone ever says anything other than YAML when referring to this markup style. This is the last of the core concepts
0:13
we're going to introduce for now so that we can get started writing our playbooks and getting comfortable actually using Ansible.
0:18
There will be other concepts that will be introduced along the way but this is the last of them that we need in order to get started
0:23
because these are the key words we're going to be using constantly to describe what we're doing. We've already seen an example of
0:29
an Ansible task written in YAML Here's what it looks like again. Let's highlight the important parts
0:33
when it comes to the YAML format versus the task itself. Now, on the first line, we have a hyphen and then a space and then a key.
0:40
The key in this case is name with a colon after it and then a value and the value in this case is ensure git is installed.
0:48
And thinking in key-value pairs is basically the core idea with YAML. Even on this next line, which looks more complicated
0:54
the key is apt, and the value itself is just three key-value pairs. The key of name is equal to git-core
1:00
that's the name of the package that we want to install. The key of state and the value of present indicating that we want
1:05
the get core package to be installed. The key of update_cache and the value of yes which tells apt that we want to update
1:13
the versions package in the package manager before we install anything. And then, on this last line, become true key of become and the value of true
1:20
indicating that we want to use our super user privileges in order to execute this task. One thing to note is that spacing is required for the syntax.
1:28
It's not just to make our tasks easier to read which it certainly does. There are two spaces before apt. There are two spaces before become.
1:35
The spacing indicates that the second and third lines are grouped together with the first line. If you were to indent or remove the indentation
1:42
from the second or third lines it would no longer be valid syntax for Ansible. So that's what YAML looks like.
1:47
That's why the spacing is as you see it in this example. And we're going to be writing a whole lot of YAML in all of our playbooks
1:53
to configure servers and play applications.