WEBVTT

1
00:00.000 --> 00:04.200
So now that we know what a basic YAML document looks like, what I want to show

2
00:04.200 --> 00:04.760
you is how

3
00:04.760 --> 00:08.520
we can create something known as key value pairs within YAML.

4
00:08.520 --> 00:10.840
So with that said, let's just dive in.

5
00:10.840 --> 00:14.380
Now one of the primary purposes of having these key value pairs is that it's

6
00:14.380 --> 00:15.040
going to allow

7
00:15.040 --> 00:18.720
you to make your data much more accessible programmatically.

8
00:18.720 --> 00:21.120
Take for example this text document.

9
00:21.120 --> 00:24.880
If you wanted some type of automation system to programmatically peel out the

10
00:24.880 --> 00:25.560
data within

11
00:25.560 --> 00:29.720
this particular paragraph, it's actually quite a complicated process.

12
00:29.720 --> 00:33.430
You would have to use things such as regular expressions to really try to match
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

12
00:29.720 --> 00:33.430
You would have to use things such as regular expressions to really try to match

13
00:33.430 --> 00:33.920
out very

14
00:33.920 --> 00:36.280
particular patterns within the text.

15
00:36.280 --> 00:39.800
And the problem with this is that there can be multiple instances of those

16
00:39.800 --> 00:40.560
patterns.

17
00:40.560 --> 00:42.800
Say for example that we wanted to parse out my name.

18
00:42.800 --> 00:46.700
Now if you happen to know that my name here is John McGovern, well it does make

19
00:46.700 --> 00:47.200
the search

20
00:47.200 --> 00:49.040
pattern a lot easier to find.

21
00:49.040 --> 00:50.680
But that is if you know what you're looking for.

22
00:50.680 --> 00:54.160
Say for example you have a whole bunch of configurations whereby you have lots

23
00:54.160 --> 00:54.600
and lots

24
00:54.600 --> 00:55.920
of data to deal with.

25
00:55.920 --> 01:00.000
Quite simply this data is far too unstructured whereas if we happen to just
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

26
01:00.000 --> 01:01.360
take this information

27
01:01.360 --> 01:06.980
here and utilize these key value pairs, we can easily access the very data that

28
01:06.980 --> 01:07.680
we want

29
01:07.680 --> 01:09.200
very very precisely.

30
01:09.200 --> 01:12.990
So say for example we could create a key called name and associated with that

31
01:12.990 --> 01:13.560
key would be

32
01:13.560 --> 01:14.880
the corresponding value.

33
01:14.880 --> 01:17.080
So John McGovern in my case.

34
01:17.080 --> 01:20.800
So if for example you want to retrieve the name from your data sets, we just

35
01:20.800 --> 01:21.280
tell the

36
01:21.280 --> 01:25.500
system to look for the name key and it will return the corresponding value in

37
01:25.500 --> 01:26.120
this case

38
01:26.120 --> 01:30.900
here, John McGovern as opposed to trying to rifle through all of this text un
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

38
01:26.120 --> 01:30.900
here, John McGovern as opposed to trying to rifle through all of this text un

39
01:30.900 --> 01:31.960
structured,

40
01:31.960 --> 01:34.640
trying to find a very particular pattern match.

41
01:34.640 --> 01:37.880
Once again this still might not be quite so clear just yet.

42
01:37.880 --> 01:41.500
But once we begin getting hands on writing these Ansible Playbooks, you're

43
01:41.500 --> 01:41.800
going to

44
01:41.800 --> 01:45.320
see that having this very strict structure really does help us when we're

45
01:45.320 --> 01:46.360
trying to engage

46
01:46.360 --> 01:47.920
an automation system.

47
01:47.920 --> 01:51.680
So let's look at some of the rules that we can use to create these key value

48
01:51.680 --> 01:52.280
pairs.

49
01:52.280 --> 01:56.230
Now before we actually dig in and begin writing these yaml files, the text

50
01:56.230 --> 01:57.320
editor that I would

51
01:57.320 --> 01:59.600
suggest you use is Vim.

52
01:59.600 --> 02:03.150
The reason being is that when it sees that dot yml extension, it's going to
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

52
01:59.600 --> 02:03.150
The reason being is that when it sees that dot yml extension, it's going to

53
02:03.150 --> 02:03.760
give you some

54
02:03.760 --> 02:07.960
nice syntax highlighting and also going to help you follow the rules of the

55
02:07.960 --> 02:09.040
indentation.

56
02:09.040 --> 02:13.240
So in this case here, I'm just going to use Vim and I will just say example dot

57
02:13.240 --> 02:13.560
yml.

58
02:13.560 --> 02:14.560
Okay.

59
02:14.560 --> 02:17.460
So if I press I for insert and have my three hyphens at the top, what I'm going

60
02:17.460 --> 02:17.760
to do

61
02:17.760 --> 02:19.360
is first create my key.

62
02:19.360 --> 02:23.850
Now the way we specify a key is just by giving the key a name and then we

63
02:23.850 --> 02:25.320
specify a colon.

64
02:25.320 --> 02:27.080
Notice the coloration change here.

65
02:27.080 --> 02:29.640
The text editor knows that we have just created the key.

66
02:29.640 --> 02:33.070
Now one thing to note is that when we create these keys, we want to leave a
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

66
02:29.640 --> 02:33.070
Now one thing to note is that when we create these keys, we want to leave a

67
02:33.070 --> 02:33.880
space before

68
02:33.880 --> 02:35.800
we pass in the value.

69
02:35.800 --> 02:41.320
So if I say space and then John McGuffin, this is absolutely valid.

70
02:41.320 --> 02:46.300
However, if I happen to just move over here and I remove the space, check out

71
02:46.300 --> 02:47.080
the syntax

72
02:47.080 --> 02:48.080
highlighting.

73
02:48.080 --> 02:49.920
Suddenly it's when read again, this is no longer the key.

74
02:49.920 --> 02:52.280
We do not have the key value pair.

75
02:52.280 --> 02:53.280
So just be aware of that.

76
02:53.280 --> 02:55.000
Like I say, Vim is going to help you.

77
02:55.000 --> 02:59.080
Now when I press return, naturally, we're going to get some type of indentation

78
02:59.080 --> 02:59.280
.

79
02:59.280 --> 03:01.160
This happens to be two spaces in.
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

79
02:59.280 --> 03:01.160
This happens to be two spaces in.

80
03:01.160 --> 03:04.080
But for now, I don't actually want to use this indentation.

81
03:04.080 --> 03:05.880
We'll talk about that very, very shortly.

82
03:05.880 --> 03:10.340
So all I will do is just press backspace once and notice it actually goes back

83
03:10.340 --> 03:11.000
two spaces

84
03:11.000 --> 03:13.280
to the correct level of indentation.

85
03:13.280 --> 03:19.290
So if I say age and then colon and then space, I can now pass in my age, which

86
03:19.290 --> 03:20.240
in this case

87
03:20.240 --> 03:21.880
here is actually 38.

88
03:21.880 --> 03:24.400
Once again, I hit enter, we try to automatically indent.

89
03:24.400 --> 03:26.440
We don't want to use this quite just yet.

90
03:26.440 --> 03:28.360
So I just press backspace again.

91
03:28.360 --> 03:32.420
Now roughly as a concept, what we're looking at here is that when we have a key
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

91
03:28.360 --> 03:32.420
Now roughly as a concept, what we're looking at here is that when we have a key

92
03:32.420 --> 03:32.920
, you can

93
03:32.920 --> 03:36.960
roughly imagine that as like a folder and the value is what is actually inside

94
03:36.960 --> 03:37.640
the folder.

95
03:37.640 --> 03:42.210
Now the way I say this is because the actual value kind of belongs to the key,

96
03:42.210 --> 03:43.080
so to speak,

97
03:43.080 --> 03:47.400
the same way that anything inside of a folder belongs to that particular folder

98
03:47.400 --> 03:47.680
.

99
03:47.680 --> 03:50.200
This might make more sense when we happen to see nested values.

100
03:50.200 --> 03:52.240
So say for example, look at this.

101
03:52.240 --> 03:55.160
What if I also wanted to add in my address, okay?

102
03:55.160 --> 03:58.720
Now inside of the address, I didn't just want to type in the entire address,

103
03:58.720 --> 03:59.080
such as maybe

104
03:59.080 --> 04:04.370
say one main street in Scotland, and then let's maybe say there's a postcode or
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

104
03:59.080 --> 04:04.370
say one main street in Scotland, and then let's maybe say there's a postcode or

105
04:04.370 --> 04:04.920
a zip code

106
04:04.920 --> 04:08.040
in the US, which is the 54321.

107
04:08.040 --> 04:11.770
Let's maybe say I wanted to break up all of this data into individual

108
04:11.770 --> 04:12.640
components by

109
04:12.640 --> 04:16.600
still wanting to all to be under the association of address.

110
04:16.600 --> 04:21.510
Well, the way we can do this is just create more key value pairs, but indent it

111
04:21.510 --> 04:22.040
within

112
04:22.040 --> 04:23.040
the address key.

113
04:23.040 --> 04:24.040
So look at this.

114
04:24.040 --> 04:28.060
If I actually don't give a value right here and I just press enter, we get this

115
04:28.060 --> 04:28.720
automatic

116
04:28.720 --> 04:29.720
indentation.

117
04:29.720 --> 04:32.520
And what I can just do is just create a new key.
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

117
04:29.720 --> 04:32.520
And what I can just do is just create a new key.

118
04:32.520 --> 04:35.910
So I could say, for example, the street that I belong to and how do I create a

119
04:35.910 --> 04:36.200
key?

120
04:36.200 --> 04:39.200
Of course, I just say colon and now look at the highlighting we have created

121
04:39.200 --> 04:40.320
another key

122
04:40.320 --> 04:43.240
and it is indented within the address key.

123
04:43.240 --> 04:46.120
So I could just say the street is one main street.

124
04:46.120 --> 04:50.260
So the next key I create is a setting, which is going to be Glasgow in Scotland

125
04:50.260 --> 04:50.320
.

126
04:50.320 --> 04:52.760
And then I could just say, say, for example, the zip code, now it doesn't

127
04:52.760 --> 04:53.320
actually make

128
04:53.320 --> 04:54.320
sense in the UK.

129
04:54.320 --> 04:57.320
We don't actually have zip codes, but nevertheless, you kind of get the drift.

130
04:57.320 --> 05:02.040
The point here is though, is because we have actually indented all of this data
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

130
04:57.320 --> 05:02.040
The point here is though, is because we have actually indented all of this data

131
05:02.040 --> 05:02.560
here, we

132
05:02.560 --> 05:05.920
know this data is effectively a child of the address.

133
05:05.920 --> 05:10.640
Basically, all of this data here is directly related to the address.

134
05:10.640 --> 05:15.200
It just has been subdivided and separated into more key value pairs.

135
05:15.200 --> 05:18.490
So the way I happen to say this was kind of like having a folder on your

136
05:18.490 --> 05:19.160
desktop.

137
05:19.160 --> 05:20.360
Let me show you what that looks like.

138
05:20.360 --> 05:22.360
So right now here, I have three folders.

139
05:22.360 --> 05:26.580
If I go into the name folder and just double click it, we have the name John Mc

140
05:26.580 --> 05:27.680
Govern inside.

141
05:27.680 --> 05:30.720
If I go back out, I can go into age double click it.
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

141
05:27.680 --> 05:30.720
If I go back out, I can go into age double click it.

142
05:30.720 --> 05:32.160
We have the value 38.

143
05:32.160 --> 05:35.520
If I go back out, if I select address.

144
05:35.520 --> 05:38.560
Inside of address, we actually have more folders.

145
05:38.560 --> 05:41.920
We have a street folder, city folder and a zip folder.

146
05:41.920 --> 05:45.760
Just in the same way here, we have a street key, city key and a zip key.

147
05:45.760 --> 05:50.280
Basically, all of this data here is contained within a greater address key.

148
05:50.280 --> 05:52.920
This is a loaner to structure and associate data accordingly.

149
05:52.920 --> 05:56.990
So if I now go into the street key or the street folder, if you wish, we see

150
05:56.990 --> 05:57.560
the value

151
05:57.560 --> 05:58.560
one main street.

152
05:58.560 --> 06:02.580
If we go back out, we go into the city key or city folder, double click it, we
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

152
05:58.560 --> 06:02.580
If we go back out, we go into the city key or city folder, double click it, we

153
06:02.580 --> 06:03.000
see the

154
06:03.000 --> 06:07.230
value is Glasgow and then finally, the zip key tells us that the zip value is 5

155
06:07.230 --> 06:08.280
4321.

156
06:08.280 --> 06:12.040
Like I said, the beauty of YAML is this human readability.

157
06:12.040 --> 06:14.000
So you just correctly eyeballing this.

158
06:14.000 --> 06:18.320
By virtue of seeing the indentation, your eyes and brain can easily interpret

159
06:18.320 --> 06:18.720
all of

160
06:18.720 --> 06:23.580
this information here as relating to and is subsequently a product of the

161
06:23.580 --> 06:24.560
address information

162
06:24.560 --> 06:26.040
that we're trying to communicate.

163
06:26.040 --> 06:29.300
So whilst this might be a very frivolous example right now, when it comes to

164
06:29.300 --> 06:30.480
creating configuration
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

164
06:29.300 --> 06:30.480
creating configuration

165
06:30.480 --> 06:33.120
files, you may have a whole bunch of nested data.

166
06:33.120 --> 06:38.480
Say, for example, a key for servers and intended within that key, you may have

167
06:38.480 --> 06:39.280
a database

168
06:39.280 --> 06:43.720
key as well as a corresponding web key and then maybe some corresponding values

169
06:43.720 --> 06:44.000
.

170
06:44.000 --> 06:49.950
Let's maybe say eight dot eight dot eight dot eight and one dot one dot one dot

171
06:49.950 --> 06:50.520
one.

172
06:50.520 --> 06:53.500
This one here could be the IP address of the web server and this one here could

173
06:53.500 --> 06:54.120
be the IP

174
06:54.120 --> 06:55.560
address of the database server.

175
06:55.560 --> 06:59.930
And again, just at a glance by virtue of the web and database keys being ind

176
06:59.930 --> 07:00.440
ented with
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

176
06:59.930 --> 07:00.440
ented with

177
07:00.440 --> 07:05.590
then the greater server key, we know here that the database in the web happens

178
07:05.590 --> 07:05.960
to be

179
07:05.960 --> 07:08.160
talking about servers explicitly.

180
07:08.160 --> 07:11.680
So the indentation and nesting allows us to correlate the data together.
