WEBVTT

1
00:00.000 --> 00:04.480
So friends in the previous video we discussed the general structure needed in

2
00:04.480 --> 00:05.520
order to create an

3
00:05.520 --> 00:09.970
Ansible role and this particular video we're going to take that information and

4
00:09.970 --> 00:10.720
actually do it for

5
00:10.720 --> 00:14.860
real. So with that said let's just get to it. So here is the plan and this

6
00:14.860 --> 00:15.920
particular video

7
00:15.920 --> 00:18.650
we're going to create a new directory structure for the role that we're going

8
00:18.650 --> 00:19.680
to be generating.

9
00:19.680 --> 00:23.700
Once again we're going to take advantage of the Ansible Galaxy and net command

10
00:23.700 --> 00:24.640
to auto generate

11
00:24.640 --> 00:29.000
this for us. Then once we have done that we're going to actually populate the

12
00:29.000 --> 00:30.640
content needed within
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

12
00:29.000 --> 00:30.640
content needed within

13
00:30.640 --> 00:34.980
the correct files. With that in play a role should be operational and then we

14
00:34.980 --> 00:36.880
're going to call a role

15
00:36.880 --> 00:41.760
from the thin Apple Book itself. Now I'm not being fully transparent here we're

16
00:41.760 --> 00:42.480
not just going to

17
00:42.480 --> 00:47.610
quickly go in and populate the files. Instead we're going to actually follow a

18
00:47.610 --> 00:49.200
very common format

19
00:49.200 --> 00:53.690
or rather should I say a very common process that generally comes about upon

20
00:53.690 --> 00:54.880
the creation of an

21
00:54.880 --> 00:59.490
Ansible role. Because quite honestly these roles are often best just from

22
00:59.490 --> 01:01.120
regular playbooks. So
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

22
00:59.490 --> 01:01.120
regular playbooks. So

23
01:01.120 --> 01:05.440
someone writes an Ansible playbook it happens to be getting used quite a lot

24
01:05.440 --> 01:06.240
and as such the

25
01:06.240 --> 01:10.950
decision is made to convert this into a role whereby it's much more portable

26
01:10.950 --> 01:11.920
and reusable.

27
01:11.920 --> 01:17.080
So as per that convention we're going to actually copy that by first actually

28
01:17.080 --> 01:18.160
creating an Ansible

29
01:18.160 --> 01:22.590
playbook and we will walk through the process of transforming that regular Ans

30
01:22.590 --> 01:23.440
ible playbook

31
01:23.440 --> 01:28.800
into a brand new shiny Ansible role. Now one thing to state just off the bat to

32
01:28.800 --> 01:30.000
be very aware of
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

33
01:30.000 --> 01:34.080
is that these Ansible roles very often not necessarily by the way but very

34
01:34.080 --> 01:34.480
often

35
01:34.480 --> 01:38.420
are designed to be shared. That is why they are published on publicly

36
01:38.420 --> 01:40.000
accessible websites such

37
01:40.000 --> 01:44.480
as Ansible Galaxy. So because of this if they are going to be shared and they

38
01:44.480 --> 01:46.320
can be freely downloaded

39
01:46.320 --> 01:49.920
you have to be very very careful that you don't actually package up any

40
01:49.920 --> 01:51.920
sensitive data inside of

41
01:51.920 --> 01:55.680
these files within the role itself. So things like passwords, things like

42
01:55.680 --> 01:57.120
sensitive configurations

43
01:57.120 --> 02:01.680
within your network that type of thing always be sure what it is you happen to
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

43
01:57.120 --> 02:01.680
within your network that type of thing always be sure what it is you happen to

44
02:01.680 --> 02:02.640
be publishing.

45
02:02.640 --> 02:06.790
So with that warming out the road let's go and begin creating an Ansible

46
02:06.790 --> 02:07.440
playbook.

47
02:07.440 --> 02:11.760
So let's just say touch let's just call this play1.yml the name itself doesn't

48
02:11.760 --> 02:12.720
actually matter and

49
02:12.720 --> 02:16.640
people go into this particular file. So I'm going to insert mode have my three

50
02:16.640 --> 02:17.840
hyphens at the top

51
02:17.840 --> 02:21.640
and I'll just say the name is playbook for multiple tasks. Okay let's just

52
02:21.640 --> 02:22.640
pretend that this playbook

53
02:22.640 --> 02:26.720
is doing it much more than I actually will configure it to do. Okay so let's

54
02:26.720 --> 02:28.160
have our host be the

55
02:28.160 --> 02:31.470
all group so that's going to be the blue box and the yellow box targeted and
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

55
02:28.160 --> 02:31.470
all group so that's going to be the blue box and the yellow box targeted and

56
02:31.470 --> 02:32.400
now what I will do is

57
02:32.400 --> 02:36.050
I'll go down and define my tasks. Okay so this is very much similar to what we

58
02:36.050 --> 02:36.880
saw before I'll

59
02:36.880 --> 02:42.020
have the name key and I'll just say maybe a task one or just a configuring DNS

60
02:42.020 --> 02:43.200
servers and what I

61
02:43.200 --> 02:47.120
will do is I'll use the Ansible built-in template module and the source is

62
02:47.120 --> 02:48.400
going to be which is

63
02:48.400 --> 02:52.530
called the file DNS dot j2 and the destination where it's going to be copied to

64
02:52.530 --> 02:53.440
the actual render

65
02:53.440 --> 02:58.180
configuration is going to be in the etsy resolve dot conf configuration of all

66
02:58.180 --> 02:59.760
of the target devices.

67
02:59.760 --> 03:04.350
So like I say this is just one simple task let me add in another one and I'll
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

67
02:59.760 --> 03:04.350
So like I say this is just one simple task let me add in another one and I'll

68
03:04.350 --> 03:05.760
just say task two

69
03:05.760 --> 03:10.070
I'm just taking figuring ntp servers and in fact I've just got a little bit of

70
03:10.070 --> 03:10.880
a typo there.

71
03:10.880 --> 03:15.040
Now in the interest of time I'm going to invoke the power of imagination and as

72
03:15.040 --> 03:15.920
opposed to writing

73
03:15.920 --> 03:19.950
multiple different templates and multiple different variables instead here I'm

74
03:19.950 --> 03:20.880
just going to simply

75
03:20.880 --> 03:25.210
type a little message here and I'll just say successfully configured ntp

76
03:25.210 --> 03:26.320
servers okay so I'm

77
03:26.320 --> 03:29.070
totally cheating here I'm not actually doing the configuration in this case

78
03:29.070 --> 03:29.680
here but it's just

79
03:29.680 --> 03:33.760
allowing you to see multiple tasks and again this one here can be task three I
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

79
03:29.680 --> 03:33.760
allowing you to see multiple tasks and again this one here can be task three I

80
03:33.760 --> 03:34.480
'm just taking

81
03:34.480 --> 03:38.880
figuring sftp and again just to keep things nice and quick let's just use that

82
03:38.880 --> 03:39.520
our imagination

83
03:39.520 --> 03:44.000
and just print out the message successfully configuring sftp okay so we have

84
03:44.000 --> 03:45.440
three different tasks one

85
03:45.440 --> 03:48.760
of which we're actually going to do for real and in the interest of time the

86
03:48.760 --> 03:49.520
other two were

87
03:49.520 --> 03:52.660
going to pretend that they were successfully configured so what we're going to

88
03:52.660 --> 03:53.200
have to do

89
03:53.200 --> 03:58.180
is to define some variables as well as to create this little ginger template

90
03:58.180 --> 03:59.360
okay so let's go and

91
03:59.360 --> 04:03.980
do that just now let's go into the host files here so I'll go into blue box dot
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

91
03:59.360 --> 04:03.980
do that just now let's go into the host files here so I'll go into blue box dot

92
04:03.980 --> 04:04.880
yml and I'm going to

93
04:04.880 --> 04:07.840
insert mode here's my three hyphens at the top for the ammo file and I'm going

94
04:07.840 --> 04:08.880
to have a key called

95
04:08.880 --> 04:14.050
DNS servers and a colon have a hyphen and then denote the actual servers I want

96
04:14.050 --> 04:15.280
to have associated

97
04:15.280 --> 04:21.980
with that particular device sauset 8.8.8.8 as well as 8.8.4.4 okay so escape

98
04:21.980 --> 04:23.600
colon wq to write and

99
04:23.600 --> 04:28.610
quit let's say vim yellow box dot yml again insert mode three hyphens make sure

100
04:28.610 --> 04:30.080
we're calling the exact
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

100
04:28.610 --> 04:30.080
we're calling the exact

101
04:30.080 --> 04:35.510
same key and in this case here the DNS servers can be 8.8.8.8 and let's move it

102
04:35.510 --> 04:37.760
to 192.168.1.1

103
04:37.760 --> 04:42.180
okay and now I will go into my templates directory and I'm going to create a

104
04:42.180 --> 04:44.480
file called DNS.j2

105
04:44.480 --> 04:48.590
so let's go in here with vim and I'm going to insert mode we don't have to have

106
04:48.590 --> 04:49.200
our hyphens

107
04:49.200 --> 04:52.940
and I'm going to say curly brace percentage to have my control logic and I'm

108
04:52.940 --> 04:54.720
going to say if DNS

109
04:54.720 --> 04:59.930
servers and then percentage curly brace pretty much meaning that if there is a

110
04:59.930 --> 05:00.960
DNS server key for a
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

110
04:59.930 --> 05:00.960
DNS server key for a

111
05:00.960 --> 05:05.710
particular host variable file we actually want to go about trying to configure

112
05:05.710 --> 05:06.720
that DNS server

113
05:06.720 --> 05:10.910
for that device now inside of that conditional statement we're going to have

114
05:10.910 --> 05:11.360
another piece of

115
05:11.360 --> 05:17.170
control logic and I'm going to loop through the DNS server so I'll just say for

116
05:17.170 --> 05:19.920
DNS in DNS servers

117
05:19.920 --> 05:24.360
and again percentage curly brace all I'm going to say is the keyword name

118
05:24.360 --> 05:25.840
server and then have my

119
05:25.840 --> 05:29.140
double curly braces for the variable value and then populate the variable I

120
05:29.140 --> 05:30.160
have selected which
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

120
05:29.140 --> 05:30.160
have selected which

121
05:30.160 --> 05:34.770
is just a word DNS now because I have opened my for loop I'm going to have to

122
05:34.770 --> 05:35.920
say curly brace

123
05:35.920 --> 05:42.440
percentage end for percentage curly brace and at the very end notice the for

124
05:42.440 --> 05:43.920
loop is encased within

125
05:43.920 --> 05:47.690
the f block so once again we're going to have to use a control block to close

126
05:47.690 --> 05:48.800
that off to so I will

127
05:48.800 --> 05:53.860
say end if again with my percentage curly brace so this should be my little

128
05:53.860 --> 05:55.600
configuration right now

129
05:55.600 --> 06:00.000
if I go back to a CD back back I find I just say answerable playbook and I try
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

130
06:00.000 --> 06:01.040
to play one dot

131
06:01.040 --> 06:06.030
yml hit enter give it a moment and look at this right here we have task one

132
06:06.030 --> 06:07.600
configured DNS servers

133
06:07.600 --> 06:11.300
we can see we have a change and for task two and task three it says

134
06:11.300 --> 06:12.240
successfully configured

135
06:12.240 --> 06:16.640
NTP servers and successfully configured SFTP wink wink we know nothing actually

136
06:16.640 --> 06:17.440
happened with

137
06:17.440 --> 06:21.020
respect to those last two tasks but again we're just pretending so it seems

138
06:21.020 --> 06:22.320
here that we have a

139
06:22.320 --> 06:26.630
working playbook and if I just happen to go to my yellow box here for example

140
06:26.630 --> 06:27.440
and I do them

141
06:27.440 --> 06:31.990
it say resolve dot conf and hit enter as we can see here the rendering has
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

141
06:27.440 --> 06:31.990
it say resolve dot conf and hit enter as we can see here the rendering has

142
06:31.990 --> 06:33.680
worked perfect so what we

143
06:33.680 --> 06:39.000
now want to do is to transform this working playbook into a working and simple

144
06:39.000 --> 06:40.160
role so I'm going to

145
06:40.160 --> 06:43.050
create the directory structure here so what is the command that's going to be

146
06:43.050 --> 06:44.560
answerable galaxy

147
06:44.560 --> 06:48.280
in it and let's just call the role my servers okay because apparently we're

148
06:48.280 --> 06:50.160
configuring SFTP servers

149
06:50.160 --> 06:55.730
NTP servers wink wink as well as a DNS server okay so let's just hit enter here

150
06:55.730 --> 06:56.320
now that role has

151
06:56.320 --> 07:00.170
been successfully created if we happen to run a tree command on it there is the
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

151
06:56.320 --> 07:00.170
been successfully created if we happen to run a tree command on it there is the

152
07:00.170 --> 07:01.200
directory structure

153
07:01.200 --> 07:04.710
needed and what we now want to do is to begin breaking down our ansable

154
07:04.710 --> 07:05.840
playbook as well as

155
07:05.840 --> 07:10.530
things like our templates and our variables and begin populating them into the

156
07:10.530 --> 07:11.680
correct files now

157
07:11.680 --> 07:15.600
one thing just to be clear here we're still going to make use of our host fires

158
07:15.600 --> 07:16.080
and group

159
07:16.080 --> 07:19.670
bars directory that doesn't actually change basically the template used is

160
07:19.670 --> 07:20.800
still going to be able to

161
07:20.800 --> 07:24.370
suck in those values and all the inheritance is still in play the variables

162
07:24.370 --> 07:25.200
that we're talking

163
07:25.200 --> 07:29.020
about here are the ones that are defined in the playbook or the role in this

164
07:29.020 --> 07:29.840
case let me show you

165
07:29.840 --> 07:33.060
what I mean so the first thing you want to do is you want to look at our ans
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

165
07:29.840 --> 07:33.060
what I mean so the first thing you want to do is you want to look at our ans

166
07:33.060 --> 07:33.920
able playbook the

167
07:33.920 --> 07:39.210
original one and begin looking at what can be made generic so let's go back

168
07:39.210 --> 07:40.560
into the play so take

169
07:40.560 --> 07:44.420
this part right here okay now again none of this is absolutely essential it's

170
07:44.420 --> 07:45.280
down to your own

171
07:45.280 --> 07:50.680
discretion but just for an example in the case here of the first task why don't

172
07:50.680 --> 07:52.560
I leave the task name

173
07:52.560 --> 07:56.550
task one hardcoded because it's always going to be the first task but perhaps

174
07:56.550 --> 07:57.840
maybe this particular

175
07:57.840 --> 08:02.340
part here the part that describes what is happening configuring DNS servers why
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

175
07:57.840 --> 08:02.340
part here the part that describes what is happening configuring DNS servers why

176
08:02.340 --> 08:03.600
don't I make that a

177
08:03.600 --> 08:08.040
variable value so that perhaps it can be populated via a different variable

178
08:08.040 --> 08:08.640
that is the type of

179
08:08.640 --> 08:12.790
variables we're talking about here similarly with respect to the source right

180
08:12.790 --> 08:14.080
here the actual j2

181
08:14.080 --> 08:19.190
templates maybe someone else wants to use a different templates so in this case

182
08:19.190 --> 08:20.080
here we can

183
08:20.080 --> 08:25.060
remove the hard coding and in this case substitute in a much more generic

184
08:25.060 --> 08:25.920
variable value that can

185
08:25.920 --> 08:29.880
just be called same again for the destination perhaps we're not going to always

186
08:29.880 --> 08:30.960
override the
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

186
08:29.880 --> 08:30.960
override the

187
08:30.960 --> 08:36.120
ec resolve.conf configuration file once again a candidate for a variable value

188
08:36.120 --> 08:36.720
so let's do the

189
08:36.720 --> 08:41.270
same thing for task two and for task three okay so let's go in here and begin

190
08:41.270 --> 08:42.400
to make this as

191
08:42.400 --> 08:46.780
generic as we can or as generic as makes sense so what I will do here is I will

192
08:46.780 --> 08:47.760
go in leave task

193
08:47.760 --> 08:51.870
one the same but this part here the description let's just have our double

194
08:51.870 --> 08:52.960
curly brace and we'll

195
08:52.960 --> 08:57.960
give it a name we'll just say task underscore one okay the DNS j2 let's remove

196
08:57.960 --> 08:58.960
this again we'll

197
08:58.960 --> 09:03.660
have a double curly brace and we'll just say task one templates okay and again
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

197
08:58.960 --> 09:03.660
have a double curly brace and we'll just say task one templates okay and again

198
09:03.660 --> 09:04.960
the destination and

199
09:04.960 --> 09:08.770
in fact let's maybe change that name from task one template and we'll go with

200
09:08.770 --> 09:09.680
task one source

201
09:09.680 --> 09:13.910
okay and again for the destination for all the same convention we'll say task

202
09:13.910 --> 09:14.880
underscore one

203
09:15.680 --> 09:18.880
this and task two again we'll leave the actual task two part but the

204
09:18.880 --> 09:20.000
description will just change

205
09:20.000 --> 09:23.710
to the variable of task underscore two and we'll remove the message here let's

206
09:23.710 --> 09:24.960
just maybe change

207
09:24.960 --> 09:28.320
the last part so we'll leave successfully configured hard coded let's give this

208
09:28.320 --> 09:29.360
a variable name of

209
09:29.360 --> 09:33.260
task two config and let's do the same thing for task three okay so again just
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

209
09:29.360 --> 09:33.260
task two config and let's do the same thing for task three okay so again just

210
09:33.260 --> 09:34.160
delete this part

211
09:34.160 --> 09:38.240
leave successfully configuring and we'll have task three config okay so right

212
09:38.240 --> 09:39.520
now this is a lot

213
09:39.520 --> 09:42.870
more generic it means that someone can control this whereby they can change the

214
09:42.870 --> 09:43.520
name here it's

215
09:43.520 --> 09:47.790
still going to be task one after all they could perhaps feed in a different

216
09:47.790 --> 09:49.120
source and perhaps a

217
09:49.120 --> 09:53.300
different destination and what we could do is for the values that previously

218
09:53.300 --> 09:54.240
existed we could

219
09:54.240 --> 09:59.280
actually populate them in the defaults file so basically any user of the role

220
09:59.280 --> 09:59.840
if they don't

221
09:59.840 --> 10:04.360
actually supply any other variables themselves they will just naturally inherit
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

221
09:59.840 --> 10:04.360
actually supply any other variables themselves they will just naturally inherit

222
10:04.360 --> 10:05.360
all of the values

223
10:05.360 --> 10:10.050
that we previously saw however if they want to change and override any values

224
10:10.050 --> 10:10.880
they could specify

225
10:10.880 --> 10:16.970
a more specific variable inside the vars directory so let's go begin defining

226
10:16.970 --> 10:18.320
those variable values

227
10:18.320 --> 10:22.710
then and let me go in to the my servers directory and then inside of the

228
10:22.710 --> 10:24.560
defaults here if i say

229
10:24.560 --> 10:29.610
vim main dot yml what i'm going to do is to go into insert mode okay so press i

230
10:29.610 --> 10:30.320
and i'll just go
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

230
10:29.610 --> 10:30.320
and i'll just go

231
10:30.320 --> 10:34.500
and define those particular variables okay so the first one is going to be task

232
10:34.500 --> 10:35.360
underscore one

233
10:35.360 --> 10:39.470
which is going to be the name presented and i'll just make the value updating d

234
10:39.470 --> 10:40.480
ns server okay so

235
10:40.480 --> 10:44.000
no one supplies a value this is the value they're going to inherit task one

236
10:44.000 --> 10:45.040
source we'll give that

237
10:45.040 --> 10:49.280
a default of dns.jtuber going to have to put this particular file into the

238
10:49.280 --> 10:50.800
correct folder of course

239
10:50.800 --> 10:56.250
we'll say task one desk that's going to be the etsy resolve.conf configuration

240
10:56.250 --> 10:57.360
file unless something

241
10:57.360 --> 11:02.510
else is specified let's say task two we're just updating i think it was ntp
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

241
10:57.360 --> 11:02.510
else is specified let's say task two we're just updating i think it was ntp

242
11:02.510 --> 11:04.240
servers i said and

243
11:04.240 --> 11:09.360
task to underscore config we'll just say the ntp servers and then we'll have

244
11:09.360 --> 11:10.480
task underscore three

245
11:10.480 --> 11:15.700
as a variable just say updating sftp and then we have the task three config

246
11:15.700 --> 11:16.960
variable which is going

247
11:16.960 --> 11:21.690
to end up reading successfully configuring the sftp servers okay now right now

248
11:21.690 --> 11:22.480
that is all the

249
11:22.480 --> 11:26.160
variables that are defined in our playbook right now which is soon to be going

250
11:26.160 --> 11:26.960
to be migrated

251
11:26.960 --> 11:31.730
into our ancable role via tasks and in fact before i do that one thing we have
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

251
11:26.960 --> 11:31.730
into our ancable role via tasks and in fact before i do that one thing we have

252
11:31.730 --> 11:32.720
to ensure is that

253
11:32.720 --> 11:37.150
this particular template the dns.jt is in the correct location so what i'm

254
11:37.150 --> 11:38.480
going to do here is if i go

255
11:38.480 --> 11:42.690
back to my home directory let's go into templates right here we can see we have

256
11:42.690 --> 11:43.840
the dns.jt if i

257
11:43.840 --> 11:47.430
cat this right here this is not going to be picked up quite just yet quite

258
11:47.430 --> 11:48.560
simply because it's in

259
11:48.560 --> 11:52.460
the wrong templates folder so all i'm going to do is copy this particular file

260
11:52.460 --> 11:53.520
i'm going to copy

261
11:53.520 --> 11:57.090
enter the correct folder within the my servers role case it's going to go into

262
11:57.090 --> 11:57.840
the templates

263
11:57.840 --> 12:01.530
directory there okay so now if i go back in and go into the my servers it
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

263
11:57.840 --> 12:01.530
directory there okay so now if i go back in and go into the my servers it

264
12:01.530 --> 12:02.640
should be copied over

265
12:02.640 --> 12:08.010
let's go into cd for the templates inside of the role itself now we have the d

266
12:08.010 --> 12:09.360
ns.jt perfect

267
12:09.360 --> 12:14.030
now we still need to have our tasks defined so here's what i'm going to do let

268
12:14.030 --> 12:14.560
me go back to my

269
12:14.560 --> 12:18.530
home directory and all i'm going to do is let me cat the play one dot yaml file

270
12:18.530 --> 12:19.280
okay and let me

271
12:19.280 --> 12:23.200
just copy the tasks here okay so copy and i'm going to go back into the

272
12:23.200 --> 12:24.800
directory structure for the

273
12:24.800 --> 12:29.570
my servers this time i'm going to go into the tasks directory and enter the

274
12:29.570 --> 12:30.800
here we have the main
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

274
12:29.570 --> 12:30.800
here we have the main

275
12:30.800 --> 12:34.370
dot yaml so if i happen to open this up okay what i'm going to do here is go

276
12:34.370 --> 12:35.360
into this yaml file

277
12:35.360 --> 12:38.790
i'm just going to paste then what i just copied there okay so here we have all

278
12:38.790 --> 12:39.840
of our tasks now

279
12:39.840 --> 12:43.490
the very first thing we're going to have to do here is actually remove the

280
12:43.490 --> 12:45.120
tasks key we no longer need

281
12:45.120 --> 12:50.380
that by virtue of the task being within this particular tasks file the key here

282
12:50.380 --> 12:51.280
is actually

283
12:51.280 --> 12:55.500
unnecessary and simple understands that everything we have defined here is

284
12:55.500 --> 12:56.880
indeed a task okay so let's

285
12:56.880 --> 13:00.810
remove this and what we're now going to have to do is to fix the indentation
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

285
12:56.880 --> 13:00.810
remove this and what we're now going to have to do is to fix the indentation

286
13:00.810 --> 13:02.000
basically out dent

287
13:02.000 --> 13:05.940
everything to the very edge okay so let's think about this we now have defined

288
13:05.940 --> 13:06.880
our answerable tasks

289
13:06.880 --> 13:11.100
within this particular file okay and we have all of these variables things like

290
13:11.100 --> 13:12.000
task one now what

291
13:12.000 --> 13:15.830
value is that going to take well it's going to take the default value that we

292
13:15.830 --> 13:17.120
just specified same here

293
13:17.120 --> 13:21.580
for task one source task one test that type of thing okay so like i say the

294
13:21.580 --> 13:22.880
value is by default

295
13:22.880 --> 13:26.880
if we go back out a directory going to defaults we're going to pick up all the

296
13:26.880 --> 13:28.000
values inside of

297
13:28.000 --> 13:32.310
here okay and populate it within that particular file we just saw similarly
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

297
13:28.000 --> 13:32.310
here okay and populate it within that particular file we just saw similarly

298
13:32.310 --> 13:34.000
notice the task one source

299
13:34.000 --> 13:38.410
is referencing something called dns.j2 if we go into the template directory

300
13:38.410 --> 13:39.920
within the role itself

301
13:39.920 --> 13:44.520
that file actually exists in this directory structure so it is going to be

302
13:44.520 --> 13:45.840
found and like i say when

303
13:45.840 --> 13:49.620
we happen to create a playbook and call the role itself if we happen to create

304
13:49.620 --> 13:50.400
the play and the

305
13:50.400 --> 13:54.060
same directory structure whereby we have a host first directory or group first

306
13:54.060 --> 13:54.640
directory

307
13:54.640 --> 13:58.610
but answerable is still going to find all of those values so they have not been

308
13:58.610 --> 13:59.760
suddenly lost just

309
13:59.760 --> 14:03.380
by virtue of using a role so if i happen to write a new playbook let's just
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

309
13:59.760 --> 14:03.380
by virtue of using a role so if i happen to write a new playbook let's just

310
14:03.380 --> 14:04.800
call this one play two

311
14:04.800 --> 14:08.970
dot yml let's have her three hyphens at the top we'll give this playbook a name

312
14:08.970 --> 14:09.600
and we'll just say

313
14:09.600 --> 14:13.740
playbook that uses a role now the host i'm going to target is going to be the

314
14:13.740 --> 14:14.800
all group now think

315
14:14.800 --> 14:19.020
about what we just did within the role we had three separate tasks of course

316
14:19.020 --> 14:19.760
two of the tasks

317
14:19.760 --> 14:23.440
were basically dummy tasks that we just mocked up but once again imagine these

318
14:23.440 --> 14:24.400
were really long

319
14:24.400 --> 14:28.880
and complex answerable tasks now because they have been wrapped up into a role

320
14:28.880 --> 14:29.680
we can just simply

321
14:29.680 --> 14:34.120
call them like this okay we just use the keyword roles colon they may ever hyp
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

321
14:29.680 --> 14:34.120
call them like this okay we just use the keyword roles colon they may ever hyp

322
14:34.120 --> 14:35.600
hen to the not array

323
14:35.600 --> 14:39.140
and let me specify all the roles we want to use while the role we happen to

324
14:39.140 --> 14:40.160
create was called

325
14:40.160 --> 14:44.680
my servers and right now that is now our answerable playbook that is all we

326
14:44.680 --> 14:45.920
need to do now to actually

327
14:45.920 --> 14:50.520
call that to reuse all that code be just simply reference the name of the role

328
14:50.520 --> 14:51.200
okay so check this

329
14:51.200 --> 14:56.220
out if i press escape colon wq write and quit if i say answerable playbook play

330
14:56.220 --> 14:57.360
two dot yml and to

331
14:57.360 --> 15:01.460
enter oh as we can see we actually have a little bit of a syntax error within
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

331
14:57.360 --> 15:01.460
enter oh as we can see we actually have a little bit of a syntax error within

332
15:01.460 --> 15:02.400
our variables

333
15:02.400 --> 15:07.280
so let's just go into the my servers go into the defaults do them main dot yml

334
15:07.280 --> 15:08.320
as we can see here i

335
15:08.320 --> 15:11.560
didn't actually close off the quotation mark so let's just put in the final

336
15:11.560 --> 15:12.880
quotation mark and let's

337
15:12.880 --> 15:16.750
try the playbook once again hit enter and bam look at this right here we've

338
15:16.750 --> 15:17.760
actually performed

339
15:17.760 --> 15:23.060
three different tasks updating DNS servers updating ntp servers this part here

340
15:23.060 --> 15:24.400
was a variable

341
15:24.400 --> 15:29.340
similarly for task three updating sftp this part here was a variable whereas

342
15:29.340 --> 15:30.160
this part here was
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

342
15:29.340 --> 15:30.160
this part here was

343
15:30.160 --> 15:34.660
hard coded and if you want to override those variables we could easily do so by

344
15:34.660 --> 15:35.680
specifying them

345
15:35.680 --> 15:40.020
and the vars directory so it's going to my servers role let's go into the vars

346
15:40.020 --> 15:40.960
directory and i'll

347
15:40.960 --> 15:44.980
go into the main dot yml file right here let's press insert for insert mode let

348
15:44.980 --> 15:45.520
's just change

349
15:45.520 --> 15:50.970
maybe the variable for task three config let's just change this to some awesome

350
15:50.970 --> 15:52.160
pizza okay let's

351
15:52.160 --> 15:56.330
press escape colon wq to write and quit if we go back to our play let's rerun

352
15:56.330 --> 15:57.680
the playbook that calls

353
15:57.680 --> 16:02.370
the role and to enter and check this out right here look at task three this
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

353
15:57.680 --> 16:02.370
the role and to enter and check this out right here look at task three this

354
16:02.370 --> 16:03.440
part here is actually

355
16:03.440 --> 16:07.470
overwritten the default so it now says the task has successfully configured

356
16:07.470 --> 16:09.200
some awesome pizza now

357
16:09.200 --> 16:13.750
like i said the beauty of having these roles is if i just wanted to perhaps do

358
16:13.750 --> 16:14.880
all these configurations

359
16:14.880 --> 16:19.810
update sftp update ntp update dns well i can just do all of that by calling

360
16:19.810 --> 16:21.120
this particular role

361
16:21.120 --> 16:25.060
but if i wanted to perhaps build upon that i can still go and begin configuring

362
16:25.060 --> 16:25.520
my own

363
16:25.520 --> 16:31.590
answerable tasks let's just say tasks name so to say task four more stuff and
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

363
16:25.520 --> 16:31.590
answerable tasks let's just say tasks name so to say task four more stuff and

364
16:31.590 --> 16:32.240
again of course

365
16:32.240 --> 16:35.830
this is a frivolous example right now i'm just printing out some text but you

366
16:35.830 --> 16:36.880
can imagine if i

367
16:36.880 --> 16:40.640
wanted to go and write another template to do another configuration all of that

368
16:40.640 --> 16:41.760
would be possible

369
16:41.760 --> 16:46.960
but look how modular this is i'm getting access to all those three tasks just

370
16:46.960 --> 16:48.000
by simply calling the

371
16:48.000 --> 16:52.190
role name and i can easily build upon that and do additional things and before

372
16:52.190 --> 16:53.120
i save this actually

373
16:53.120 --> 16:57.530
let me just fix the indentation here if i press escape colon wq to write and

374
16:57.530 --> 16:58.640
quit let's rerun the

375
16:58.640 --> 17:02.450
playbook check this out right here look at this scrolling on up we have the
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

375
16:58.640 --> 17:02.450
playbook check this out right here look at this scrolling on up we have the

376
17:02.450 --> 17:03.680
first three tasks as

377
17:03.680 --> 17:07.910
called by the answerable role and at the very end we have just added on our own

378
17:07.910 --> 17:08.880
custom task

379
17:08.880 --> 17:13.680
just like that this is the beauty power and portability of the answerable role
