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
0:02 that stands for YAML Ain't Markup Language.
0:04 That's probably just going to be trivia for you
0:06 hardly anyone ever says anything other than YAML
0:08 when referring to this markup style.
0:10 This is the last of the core concepts
0:12 we're going to introduce for now
0:13 so that we can get started writing our playbooks
0:15 and getting comfortable actually using Ansible.
0:17 There will be other concepts
0:18 that will be introduced along the way
0:20 but this is the last of them
0:21 that we need in order to get started
0:22 because these are the key words
0:24 we're going to be using constantly
0:25 to describe what we're doing.
0:26 We've already seen an example of
0:28 an Ansible task written in YAML
0:30 Here's what it looks like again.
0:31 Let's highlight the important parts
0:32 when it comes to the YAML format versus the task itself.
0:36 Now, on the first line, we have
0:37 a hyphen and then a space and then a key.
0:39 The key in this case is name
0:41 with a colon after it and then a value
0:44 and the value in this case is ensure git is installed.
0:47 And thinking in key-value pairs
0:48 is basically the core idea with YAML.
0:50 Even on this next line, which looks more complicated
0:53 the key is apt, and the value itself
0:55 is just three key-value pairs.
0:57 The key of name is equal to git-core
0:59 that's the name of the package that we want to install.
1:01 The key of state and the value of present
1:03 indicating that we want
1:04 the get core package to be installed.
1:06 The key of update_cache and the value of yes
1:09 which tells apt that we want to update
1:12 the versions package in the package manager
1:14 before we install anything.
1:15 And then, on this last line, become true
1:17 key of become and the value of true
1:19 indicating that we want to use our super user privileges
1:22 in order to execute this task.
1:24 One thing to note is that spacing
1:26 is required for the syntax.
1:27 It's not just to make our tasks easier to read
1:30 which it certainly does.
1:31 There are two spaces before apt.
1:33 There are two spaces before become.
1:34 The spacing indicates that the second and third lines
1:37 are grouped together with the first line.
1:39 If you were to indent or remove the indentation
1:41 from the second or third lines
1:43 it would no longer be valid syntax for Ansible.
1:45 So that's what YAML looks like.
1:46 That's why the spacing is as you see it in this example.
1:49 And we're going to be writing a whole lot of YAML
1:51 in all of our playbooks
1:52 to configure servers and play applications.