WEBVTT

1
00:00.000 --> 00:04.280
Okay friends, so let's continue on looking at how we can actually utilise lips

2
00:04.280 --> 00:04.480
with an

3
00:04.480 --> 00:05.480
answerable.

4
00:05.480 --> 00:09.260
This time though, we will look at some slightly more complex lips and we will

5
00:09.260 --> 00:09.920
explore some

6
00:09.920 --> 00:14.640
simple examples whereby we use lips to make changes on other managed devices as

7
00:14.640 --> 00:15.240
opposed

8
00:15.240 --> 00:18.120
to simply just printing out text on our screen.

9
00:18.120 --> 00:21.640
So with that said, let's get to it and just dive on in.

10
00:21.640 --> 00:22.640
So let's imagine this, okay.

11
00:22.640 --> 00:24.760
What I will do is I will create a new playbook.

12
00:24.760 --> 00:29.810
I'll just call this loop2.yml because as you know, I'm always very, very

13
00:29.810 --> 00:30.920
creative.
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

13
00:29.810 --> 00:30.920
creative.

14
00:30.920 --> 00:33.080
And what I will do is I'll give this playbook a name.

15
00:33.080 --> 00:36.450
I'm just going to say testing some nested data because right now, what I'm

16
00:36.450 --> 00:37.320
going to do is

17
00:37.320 --> 00:41.270
simply print out more information like before, but I'm going to access the

18
00:41.270 --> 00:42.600
information utilising

19
00:42.600 --> 00:45.560
lips when the data is indeed nested.

20
00:45.560 --> 00:48.860
Once we have that under a belt, we'll actually begin applying it to the devices

21
00:48.860 --> 00:49.520
themselves.

22
00:49.520 --> 00:52.820
So right now, I will just have this target my local host because I'm just

23
00:52.820 --> 00:53.360
printing

24
00:53.360 --> 00:54.360
it out.

25
00:54.360 --> 00:56.920
So what I will do is I'll just define some var within the playbook.

26
00:56.920 --> 01:00.050
So I'll have a key called trainers for the CBT Nuggets trainers and I'll
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

26
00:56.920 --> 01:00.050
So I'll have a key called trainers for the CBT Nuggets trainers and I'll

27
01:00.050 --> 01:00.680
specify the

28
01:00.680 --> 01:01.680
name.

29
01:01.680 --> 01:05.290
So let's use the name key and we'll specify James for the first name and then

30
01:05.290 --> 01:05.680
we'll have

31
01:05.680 --> 01:09.630
a key called subjects and this will define some of the subjects that this

32
01:09.630 --> 01:10.720
particular trainer

33
01:10.720 --> 01:11.720
happens to teach.

34
01:11.720 --> 01:17.320
So we can say Microsoft, James also teaches Linux as well as cybersecurity.

35
01:17.320 --> 01:20.820
Now out then to within at the same level of indentation, we'll specify another

36
01:20.820 --> 01:21.320
name.

37
01:21.320 --> 01:23.200
We'll have a trainer called Keith.

38
01:23.200 --> 01:27.850
The subjects that Keith is going to teach is going to be networking and virtual

39
01:27.850 --> 01:28.440
isation

40
01:28.440 --> 01:29.960
and maybe I'll add myself in.

41
01:29.960 --> 01:35.280
I'll say John subjects I teach Linux automation and I can also tell you a lot
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

41
01:29.960 --> 01:35.280
I'll say John subjects I teach Linux automation and I can also tell you a lot

42
01:35.280 --> 01:36.440
about pizza.

43
01:36.440 --> 01:37.960
True thing I'm actually an expert.

44
01:37.960 --> 01:41.720
Okay, so what I'm going to do now is I'm going to create my tasks.

45
01:41.720 --> 01:44.980
So at the same level of indentation as the variables here, I'm going to out

46
01:44.980 --> 01:45.720
dent and choose

47
01:45.720 --> 01:46.720
tasks right here.

48
01:46.720 --> 01:51.160
I'll give the task a name and the name will just simply be printing out some

49
01:51.160 --> 01:52.600
nested data.

50
01:52.600 --> 01:58.260
So we're going to use the debug module and the message is going to be my name

51
01:58.260 --> 01:58.840
is and

52
01:58.840 --> 02:02.560
then we're going to happen to have the name of the trainer and then we'll say
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

52
01:58.840 --> 02:02.560
then we're going to happen to have the name of the trainer and then we'll say

53
02:02.560 --> 02:03.800
and I teach

54
02:03.800 --> 02:06.320
and then we'll also have our subjects.

55
02:06.320 --> 02:09.800
So here is the thing we actually want to look through the trainers.

56
02:09.800 --> 02:15.080
Okay, that will give us access to this object upon first iteration and then the

57
02:15.080 --> 02:15.760
next time

58
02:15.760 --> 02:20.050
we look around, we get the next elements in the array, which is this right here

59
02:20.050 --> 02:20.520
and I've

60
02:20.520 --> 02:23.040
just noticed that I misspelled virtualization.

61
02:23.040 --> 02:24.880
Let me just temporarily correct that.

62
02:24.880 --> 02:29.290
So the next iteration, we get access to this element here and then once that's

63
02:29.290 --> 02:29.880
done, we

64
02:29.880 --> 02:32.480
get access to the third and final element of the array.
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

64
02:29.880 --> 02:32.480
get access to the third and final element of the array.

65
02:32.480 --> 02:36.250
Now, the cool thing is, or rather the interesting thing is that we're going to

66
02:36.250 --> 02:37.000
have to parse

67
02:37.000 --> 02:39.840
out different pieces of information for each iteration.

68
02:39.840 --> 02:43.080
So the example here would be the first time we look around when we see, hi, my

69
02:43.080 --> 02:44.320
name is,

70
02:44.320 --> 02:48.900
we actually just want to access this very particular piece of information,

71
02:48.900 --> 02:49.120
which is

72
02:49.120 --> 02:50.880
going to be defined via the name key.

73
02:50.880 --> 02:56.600
In with respect to the subjects, similarly, we want to access just the subject

74
02:56.600 --> 02:57.120
key and

75
02:57.120 --> 03:00.400
get the whole list of subjects that the trainer happens to teach.
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

75
02:57.120 --> 03:00.400
get the whole list of subjects that the trainer happens to teach.

76
03:00.400 --> 03:03.140
So the way we're actually going to access this information is we're first going

77
03:03.140 --> 03:03.840
to specify

78
03:03.840 --> 03:05.720
what we're going to look through.

79
03:05.720 --> 03:09.950
So very important at the same level of indentation as the debug module, I'm

80
03:09.950 --> 03:11.000
going to specify

81
03:11.000 --> 03:14.000
loop and what is it do I actually want to loop through?

82
03:14.000 --> 03:19.080
Well, I want to loop through as we just discussed, the trainers key right here.

83
03:19.080 --> 03:22.560
So within my double parentheses, I will specify trainers.

84
03:22.560 --> 03:25.600
So that's going to give me access to each object.

85
03:25.600 --> 03:30.180
Now, if I just happen to type out item and then item again, we're going to have
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

85
03:25.600 --> 03:30.180
Now, if I just happen to type out item and then item again, we're going to have

86
03:30.180 --> 03:30.600
a bit

87
03:30.600 --> 03:31.600
of a problem.

88
03:31.600 --> 03:33.200
Let me just save this and show you what happens.

89
03:33.200 --> 03:37.080
So if I say Ansible Playbook, loop two dot y, I'm going to enter.

90
03:37.080 --> 03:39.120
So here is what we actually see here.

91
03:39.120 --> 03:41.680
Now, this might be a little bit hard to look at because we have so much

92
03:41.680 --> 03:42.440
information, but

93
03:42.440 --> 03:44.440
let's just look at the first block here.

94
03:44.440 --> 03:46.040
Okay, the first bit is outputted.

95
03:46.040 --> 03:50.610
What it says here is high, my name is, and as opposed to just saying James, it

96
03:50.610 --> 03:51.200
gives us

97
03:51.200 --> 03:52.200
absolutely everything.

98
03:52.200 --> 03:55.930
You see that it gives us the entire object included in the color braces, we see

99
03:55.930 --> 03:56.440
the name

100
03:56.440 --> 04:01.810
key as well as James, as well as the subjects, Microsoft, Linux, cybersecurity,
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

100
03:56.440 --> 04:01.810
key as well as James, as well as the subjects, Microsoft, Linux, cybersecurity,

101
04:01.810 --> 04:02.440
and then it

102
04:02.440 --> 04:08.320
says, and I teach name James, subjects, Microsoft, Linux, cybersecurity.

103
04:08.320 --> 04:11.670
So what we want to do here is we also want to be able to access the individual

104
04:11.670 --> 04:12.040
keys as

105
04:12.040 --> 04:13.240
we look around.

106
04:13.240 --> 04:15.240
So the way we do this, quite simple.

107
04:15.240 --> 04:18.860
So the important thing is we're still going to reference that very crucial item

108
04:18.860 --> 04:19.400
keyword.

109
04:19.400 --> 04:22.880
The difference is we're just going to use dot notation as we discussed in an

110
04:22.880 --> 04:23.360
earlier

111
04:23.360 --> 04:25.480
scale to access the elements within.

112
04:25.480 --> 04:30.690
So if we just say item and then say dot name to access the name and if we want
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

112
04:25.480 --> 04:30.690
So if we just say item and then say dot name to access the name and if we want

113
04:30.690 --> 04:31.520
to access

114
04:31.520 --> 04:36.520
the subjects, we say item, which gives us access to the entire element here.

115
04:36.520 --> 04:40.210
And by specifying subjects, we only parse out this piece of the data as opposed

116
04:40.210 --> 04:40.920
, including

117
04:40.920 --> 04:43.000
the name key and corresponding value.

118
04:43.000 --> 04:47.240
Now what I will do here is I'll say item dot subjects to call that key.

119
04:47.240 --> 04:52.290
And if I now save this to escape wq to write and quit, let's clear the screen,

120
04:52.290 --> 04:52.960
arrow up

121
04:52.960 --> 04:53.960
and to enter.

122
04:53.960 --> 04:54.960
Okay.

123
04:54.960 --> 04:56.920
So now we get a response, we see the message is much shorter.

124
04:56.920 --> 05:00.960
So we can see here, if we look at this one, it says, hi, my name is James and I
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

124
04:56.920 --> 05:00.960
So we can see here, if we look at this one, it says, hi, my name is James and I

125
05:00.960 --> 05:01.400
teach

126
05:01.400 --> 05:03.520
Microsoft, Linux, and cybersecurity.

127
05:03.520 --> 05:04.820
That sounds good.

128
05:04.820 --> 05:09.320
Next iteration, it says, hi, my name is Keith and I teach networking and

129
05:09.320 --> 05:10.720
virtualization.

130
05:10.720 --> 05:14.860
And finally, it says, hi, my name is John and I teach Linux automation and

131
05:14.860 --> 05:15.520
pizza, of

132
05:15.520 --> 05:16.520
course.

133
05:16.520 --> 05:18.890
So as we can see here, this is very, very similar to what we talked about when

134
05:18.890 --> 05:19.560
we discussed

135
05:19.560 --> 05:21.680
parsing out data within YAML.

136
05:21.680 --> 05:24.330
The key distinction here is that we have to be very careful about what we're

137
05:24.330 --> 05:24.720
actually

138
05:24.720 --> 05:25.720
choosing to loop through.

139
05:25.720 --> 05:27.800
In this case here, the trainer's key.

140
05:27.800 --> 05:31.120
And remember that we're still going to reference the item keyword.
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

140
05:27.800 --> 05:31.120
And remember that we're still going to reference the item keyword.

141
05:31.120 --> 05:35.060
But when we want to get more specific pieces of data from each iteration, we

142
05:35.060 --> 05:35.680
can still

143
05:35.680 --> 05:38.320
use with item keyword that dot notation.

144
05:38.320 --> 05:39.320
Okay.

145
05:39.320 --> 05:42.530
So we'll go to the screen and what I will do is I will create a new playbook

146
05:42.530 --> 05:43.120
just called

147
05:43.120 --> 05:44.840
loop three dot YML.

148
05:44.840 --> 05:48.140
So let's go into insert mode, have my three hyphens at the top and we'll just

149
05:48.140 --> 05:48.680
give this

150
05:48.680 --> 05:54.720
playbook a name and let's just say, creating some directories with loops.

151
05:54.720 --> 05:55.720
Okay.

152
05:55.720 --> 05:56.720
So what are we going to target?

153
05:56.720 --> 05:59.690
We're going to target the all group, which will be my yellow box and blue box

154
05:59.690 --> 06:00.160
machines
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

154
05:59.690 --> 06:00.160
machines

155
06:00.160 --> 06:04.480
that I'm managing and the tasks I'm going to create, let's just say tasks and

156
06:04.480 --> 06:04.720
then I'll

157
06:04.720 --> 06:08.840
have a name for the task or just a creating a directory.

158
06:08.840 --> 06:13.310
What we want to do right now is we want to use the Ansible built in file module

159
06:13.310 --> 06:13.640
.

160
06:13.640 --> 06:16.900
Now, if we recall from a previous scale that is going to have one very

161
06:16.900 --> 06:18.160
particular required

162
06:18.160 --> 06:21.720
parameter and that is the path parameter as per the documentation.

163
06:21.720 --> 06:26.430
And now within my quotation marks, I specify the file path that I want to use

164
06:26.430 --> 06:27.080
here.

165
06:27.080 --> 06:29.930
So let's maybe say I want to go into the temp directory and I wanted to create

166
06:29.930 --> 06:30.240
a file
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

166
06:29.930 --> 06:30.240
a file

167
06:30.240 --> 06:32.600
called, oh, I don't know, john one.

168
06:32.600 --> 06:33.600
Okay.

169
06:33.600 --> 06:34.600
We could do such a thing.

170
06:34.600 --> 06:35.600
Okay.

171
06:35.600 --> 06:38.380
Now what I would do is I specify the state is going to be a directory because

172
06:38.380 --> 06:38.760
that's

173
06:38.760 --> 06:39.760
where it is.

174
06:39.760 --> 06:40.760
It's not going to be a file.

175
06:40.760 --> 06:44.760
Now, as it transpires at the moment, the way this is set up is all we're going

176
06:44.760 --> 06:45.560
to do

177
06:45.560 --> 06:49.740
is we're going to target both of our machines via the all keyword, i.e. the all

178
06:49.740 --> 06:50.320
group.

179
06:50.320 --> 06:53.050
And for both machines inside of the temp directory, we're going to have a

180
06:53.050 --> 06:54.120
directory called john

181
06:54.120 --> 06:55.120
one.

182
06:55.120 --> 06:59.590
What we want to do though is we want to create multiple different directories

183
06:59.590 --> 07:00.800
also, for example,
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

183
06:59.590 --> 07:00.800
also, for example,

184
07:00.800 --> 07:02.560
within the temp directory.

185
07:02.560 --> 07:03.880
So let's think about it.

186
07:03.880 --> 07:08.410
If it's inside of the temp directory for each directory that we want to create,

187
07:08.410 --> 07:08.640
we can

188
07:08.640 --> 07:12.360
just leave this as a test as a hard coded value, because that is not going to

189
07:12.360 --> 07:12.880
change.

190
07:12.880 --> 07:17.760
The thing that is going to change is going to be the name of the directory

191
07:17.760 --> 07:18.600
itself.

192
07:18.600 --> 07:21.950
This is the part that's going to have the variation, i.e. this is the part that

193
07:21.950 --> 07:22.200
's going

194
07:22.200 --> 07:23.880
to be the variable value.

195
07:23.880 --> 07:27.300
So the first thing we're going to do here is we're going to swap out the hard

196
07:27.300 --> 07:27.680
coded

197
07:27.680 --> 07:28.680
configuration.

198
07:28.680 --> 07:32.680
So let's just remove this and I'll have my double color braces.
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

198
07:28.680 --> 07:32.680
So let's just remove this and I'll have my double color braces.

199
07:32.680 --> 07:36.920
Now what I'm going to have to do is I'm going to have to specify what it is I

200
07:36.920 --> 07:37.720
want to look

201
07:37.720 --> 07:38.720
through.

202
07:38.720 --> 07:41.890
Now at the same level of indentation as the file module, and the same way we

203
07:41.890 --> 07:42.640
talked about

204
07:42.640 --> 07:46.930
it as the same level of indentation via the debug module, what I'm going to do

205
07:46.930 --> 07:47.320
is to

206
07:47.320 --> 07:49.120
use that loop keyword once again.

207
07:49.120 --> 07:51.880
Now we're going to have multiple different things that we're going to look

208
07:51.880 --> 07:52.480
through, multiple

209
07:52.480 --> 07:53.920
different items that is.

210
07:53.920 --> 07:55.320
So how are we going to define this?

211
07:55.320 --> 07:56.840
We're going to define it as an array.

212
07:56.840 --> 08:00.880
So we'll have our hyphen and the first directory is going to be john one.
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

212
07:56.840 --> 08:00.880
So we'll have our hyphen and the first directory is going to be john one.

213
08:00.880 --> 08:04.080
The next directory is going to be john two and the third directory is going to

214
08:04.080 --> 08:04.520
be a pizza

215
08:04.520 --> 08:06.400
three because pizza is awesome.

216
08:06.400 --> 08:08.320
Oh, that is going to be the plan.

217
08:08.320 --> 08:11.670
Now just to be clear here, we're not creating a nested directory with all of

218
08:11.670 --> 08:12.520
these elements.

219
08:12.520 --> 08:13.760
For that, we would not need a look.

220
08:13.760 --> 08:15.440
We could just do it in one fell swoop.

221
08:15.440 --> 08:20.340
We could just say temp forward slash john one forward slash john two forward

222
08:20.340 --> 08:21.200
slash pizza

223
08:21.200 --> 08:22.200
three, that type of thing.

224
08:22.200 --> 08:23.200
Okay.

225
08:23.200 --> 08:27.060
What we are looking to do is to create three distinct directories temp john one

226
08:27.060 --> 08:27.360
and then

227
08:27.360 --> 08:31.160
temp john two and then temp pizza three.
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

227
08:27.360 --> 08:31.160
temp john two and then temp pizza three.

228
08:31.160 --> 08:34.400
So these directories will all be at the same level as each other.

229
08:34.400 --> 08:38.480
So think about it, if we use the item keyword, what does that actually give us?

230
08:38.480 --> 08:42.320
It gives us access to each element that we happen to be looking through.

231
08:42.320 --> 08:43.680
So the first element is john one.

232
08:43.680 --> 08:44.680
The next one is john two.

233
08:44.680 --> 08:45.760
The third is pizza three.

234
08:45.760 --> 08:47.680
Do we have to use documentation here?

235
08:47.680 --> 08:52.150
Absolutely not because the data is not nested by simply referencing item that

236
08:52.150 --> 08:53.000
will give us

237
08:53.000 --> 08:55.520
the exact data that we want to populate.

238
08:55.520 --> 08:56.680
So let's go down here.

239
08:56.680 --> 09:00.080
I'll press escape colon wq to write and quit.
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

239
08:56.680 --> 09:00.080
I'll press escape colon wq to write and quit.

240
09:00.080 --> 09:01.080
Let's clear the screen.

241
09:01.080 --> 09:06.400
Let's say answerable playbook, lip three dot yml and to enter and we'll begins.

242
09:06.400 --> 09:10.380
And look at this right here, we have a change on the yellow box as well as a

243
09:10.380 --> 09:11.160
blue box.

244
09:11.160 --> 09:15.490
And we can see here in the summary, the item on the first iteration was john

245
09:15.490 --> 09:16.160
one for both

246
09:16.160 --> 09:20.650
devices and then the next iteration, the item happened to be john two as it

247
09:20.650 --> 09:21.240
says for

248
09:21.240 --> 09:22.240
both devices.

249
09:22.240 --> 09:25.890
And then of course, we can see the item is pizza three for the two devices blue

250
09:25.890 --> 09:26.240
box in

251
09:26.240 --> 09:27.240
yellow box.

252
09:27.240 --> 09:30.520
So if we go to these devices, if we just log in, type in the password, let's
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

252
09:27.240 --> 09:30.520
So if we go to these devices, if we just log in, type in the password, let's

253
09:30.520 --> 09:31.000
open up

254
09:31.000 --> 09:32.000
our terminal.

255
09:32.000 --> 09:35.880
If I go into the temp directory, doing LS, look at what we actually see here.

256
09:35.880 --> 09:38.720
We have the john one directory john two and pizza three.

257
09:38.720 --> 09:41.600
So that means I can go into john one to a pwd.

258
09:41.600 --> 09:42.600
There we have it.

259
09:42.600 --> 09:45.400
If I see the out, I'm going to john two pwd.

260
09:45.400 --> 09:46.400
There's the path.

261
09:46.400 --> 09:49.320
And again, I can go into pizza three pwd.

262
09:49.320 --> 09:52.360
There's a path or pizza three over on the blue box.

263
09:52.360 --> 09:56.040
If we see the into the temp directory, do a listing as we can see here, similar

264
09:56.040 --> 09:56.360
way.

265
09:56.360 --> 09:59.080
We also have john one john two and pizza three.

266
09:59.080 --> 10:00.800
So I'm just CD john one.
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

266
09:59.080 --> 10:00.800
So I'm just CD john one.

267
10:00.800 --> 10:01.800
There we go.

268
10:01.800 --> 10:07.130
I can see the out and going to john two and CD back out and go into pizza three

269
10:07.130 --> 10:07.480
.

270
10:07.480 --> 10:11.070
So that's how we can access nested data within our lips, as well as how we can

271
10:11.070 --> 10:11.960
actually use

272
10:11.960 --> 10:15.000
lips to affect changes on our managed devices.
