WEBVTT

1
00:00.000 --> 00:04.320
So friends in the previous nugget we learned that we could create our own

2
00:04.320 --> 00:09.120
Ansible roles. What we would have to do though is to create them according to a

3
00:09.120 --> 00:10.240
very specific

4
00:10.240 --> 00:14.220
directory structure. That structure is what we're going to talk about right now

5
00:14.220 --> 00:14.880
. So the first thing

6
00:14.880 --> 00:19.250
to state about this particular directory structure is that the top level folder

7
00:19.250 --> 00:20.480
, i.e. the roots of

8
00:20.480 --> 00:25.310
the directory structure, that particular folder is going to be the name of the

9
00:25.310 --> 00:26.320
role itself. And

10
00:26.320 --> 00:30.790
it's going to be this name that you reference in other playbooks when you want
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

10
00:26.320 --> 00:30.790
it's going to be this name that you reference in other playbooks when you want

11
00:30.790 --> 00:31.520
to call that

12
00:31.520 --> 00:35.000
particular role. So let's maybe say you created a whole bunch of different

13
00:35.000 --> 00:35.680
tasks that we're going

14
00:35.680 --> 00:39.370
to maybe perhaps do some DNS updates. Okay. Now like you say this is something

15
00:39.370 --> 00:40.080
you do pretty

16
00:40.080 --> 00:43.970
regularly, fairly complex. So you wrap it up into a role and this is what it's

17
00:43.970 --> 00:45.120
called DNS

18
00:45.120 --> 00:48.470
underscore updates. Because this is what is going to be referenced in the

19
00:48.470 --> 00:49.600
actual playbook because

20
00:49.600 --> 00:54.560
that will be the name of the role. As such at the top level directory, I even

21
00:54.560 --> 00:55.680
would do it an MKD

22
00:55.680 --> 00:59.600
if we happen to create this manually, you would actually use that very

23
00:59.600 --> 01:01.280
particular naming convention,
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

23
00:59.600 --> 01:01.280
particular naming convention,

24
01:01.280 --> 01:05.260
the name of the role itself. And inside of that particular directory would be

25
01:05.260 --> 01:06.800
all of the subfolders

26
01:06.800 --> 01:10.450
necessary. Now I just referenced that we could actually create this directory

27
01:10.450 --> 01:11.520
structure manually,

28
01:11.520 --> 01:15.810
but quite honestly, this is not the way I happen to do this. The good news as

29
01:15.810 --> 01:16.640
we're going to learn

30
01:16.640 --> 01:21.460
is that Ansible actually has a very particular utility that is going to allow

31
01:21.460 --> 01:22.720
us to automatically

32
01:22.720 --> 01:26.240
generate the directory structure. So pretty much this will give us a nice

33
01:26.240 --> 01:27.440
little template and we

34
01:27.440 --> 01:31.120
can basically modify things as we need. One thing you will notice though is
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

34
01:27.440 --> 01:31.120
can basically modify things as we need. One thing you will notice though is

35
01:31.120 --> 01:32.640
that when we automatically

36
01:32.640 --> 01:36.670
generate the directory structure is going to give you all the structure that

37
01:36.670 --> 01:37.920
you may possibly need,

38
01:37.920 --> 01:41.850
meaning that if you happen to create as what we're going to do a rather simple

39
01:41.850 --> 01:43.040
role, we may actually

40
01:43.040 --> 01:47.480
have many unused directories. But hey, quite honestly, that is a trade off I'm

41
01:47.480 --> 01:48.880
willing to take. So in

42
01:48.880 --> 01:53.000
my humble opinion, this is definitely the easiest way to get us going. So we

43
01:53.000 --> 01:54.000
know the top level

44
01:54.000 --> 01:58.270
directory is going to be the name of the role. What then is actually going to

45
01:58.270 --> 02:00.160
be the subfolders?
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

45
01:58.270 --> 02:00.160
be the subfolders?

46
02:00.160 --> 02:03.610
Well, to answer that question, why don't we just automatically generate the

47
02:03.610 --> 02:04.720
directory structure

48
02:04.720 --> 02:08.330
and talk about what we find. So recall in the previous video, I happened to

49
02:08.330 --> 02:09.360
mention a type of

50
02:09.360 --> 02:13.590
marketplace for Ansible roles whereby you can get the roles created by more

51
02:13.590 --> 02:14.960
experienced community

52
02:14.960 --> 02:19.080
members. That particular place happened to be called Ansible Galaxy. And for

53
02:19.080 --> 02:20.560
clarity, if you so wish,

54
02:20.560 --> 02:24.720
you can absolutely publish your own roles to this particular market. But well,

55
02:24.720 --> 02:25.600
this is a kind of

56
02:25.600 --> 02:29.580
online repository for Ansible roles. This is also the actual command that we're

57
02:29.580 --> 02:30.720
going to use to
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

57
02:29.580 --> 02:30.720
going to use to

58
02:30.720 --> 02:36.190
generate a role structure. So check this out. I'm going to say Ansible hyphen

59
02:36.190 --> 02:37.200
galaxy. And then I

60
02:37.200 --> 02:40.960
will say a net for initialize and now I will give the name of the role that I

61
02:40.960 --> 02:42.240
want to create. So

62
02:42.240 --> 02:46.990
again, this could be absolutely any name you so wish very often a good idea

63
02:46.990 --> 02:48.160
would be to have a

64
02:48.160 --> 02:51.840
descriptive name. So maybe you would call the role create users if the whole

65
02:51.840 --> 02:52.880
purpose was to create

66
02:52.880 --> 02:56.900
user accounts that type of thing. But in this case here, I will just call the

67
02:56.900 --> 02:57.840
role CBT example.

68
02:57.840 --> 03:03.120
Okay. So if I hit enter here, notice it says the role CBT underscore example
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

68
02:57.840 --> 03:03.120
Okay. So if I hit enter here, notice it says the role CBT underscore example

69
03:03.120 --> 03:04.720
was created successfully.

70
03:04.720 --> 03:09.030
So if I now do an LS, here we can see the actual directory structure CBT

71
03:09.030 --> 03:10.640
example. Now, if I happen

72
03:10.640 --> 03:15.780
to say tree on that particular directory and to enter, we see all of the child

73
03:15.780 --> 03:16.880
subfolders of this

74
03:16.880 --> 03:21.790
directory, as well as a whole bunch of files. So let's work from top to bottom

75
03:21.790 --> 03:23.120
then, shall we?

76
03:23.120 --> 03:27.520
So at the very top here, we can see this folder called defaults. And inside of

77
03:27.520 --> 03:28.640
this folder, we have

78
03:28.640 --> 03:34.200
a file called main dot YML. Now the whole purpose of this particular folder
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

78
03:28.640 --> 03:34.200
a file called main dot YML. Now the whole purpose of this particular folder

79
03:34.200 --> 03:35.680
here is to hold well,

80
03:35.680 --> 03:39.500
no surprises, default values. But what default values are we talking about? We

81
03:39.500 --> 03:40.240
're actually talking

82
03:40.240 --> 03:44.940
about default variable values that are going to be used within the role pretty

83
03:44.940 --> 03:45.600
much you can

84
03:45.600 --> 03:49.730
conceptualize this as having some type of sensible default values. So for

85
03:49.730 --> 03:50.720
someone who is using the

86
03:50.720 --> 03:54.790
role, if they don't specify another variable of their own, they will actually

87
03:54.790 --> 03:56.000
inherit the defaults

88
03:56.000 --> 03:59.440
that you have set for them. So the whole point to note here is that these are

89
03:59.440 --> 04:00.400
very possibly and
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

89
03:59.440 --> 04:00.400
very possibly and

90
04:00.400 --> 04:04.070
almost even probably going to be overwritten in some forum. That really has the

91
04:04.070 --> 04:05.120
whole purpose of

92
04:05.120 --> 04:08.680
that particular file within the defaults folder. Now the next one we actually

93
04:08.680 --> 04:09.840
see here is one

94
04:09.840 --> 04:13.630
folder called files. Okay, now right now, as we can see, there is nothing

95
04:13.630 --> 04:14.560
actually inside of this

96
04:14.560 --> 04:18.100
directory. It's just completely empty. The whole purpose therefore of this

97
04:18.100 --> 04:19.680
particular directory

98
04:19.680 --> 04:23.600
is that it is a place that you can house your static files that are going to be

99
04:23.600 --> 04:24.240
used by the

100
04:24.240 --> 04:27.610
tasks within the role. So what's going to be saying here is your Ansible

101
04:27.610 --> 04:28.640
control mode right here.

102
04:28.640 --> 04:32.290
Let me just draw this out. And let's maybe have a managed device here. So it's
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

102
04:28.640 --> 04:32.290
Let me just draw this out. And let's maybe have a managed device here. So it's

103
04:32.290 --> 04:33.040
a device one.

104
04:33.040 --> 04:35.890
And let's say device number two, again, there could be many more devices you

105
04:35.890 --> 04:37.280
happen to be managing.

106
04:37.280 --> 04:42.400
And suppose you happen to have a file that exists on the Ansible control mode,

107
04:42.400 --> 04:42.880
and you want to be

108
04:42.880 --> 04:47.130
able to push that particular file to the managed nodes over here. Okay, that

109
04:47.130 --> 04:48.640
static file that exists

110
04:48.640 --> 04:52.650
on the control node that you want to be present on the targets when you are

111
04:52.650 --> 04:53.840
using roles, the place

112
04:53.840 --> 04:58.390
whereby you would define that particular file would be in that files folder.

113
04:58.390 --> 04:59.280
And in fact, this

114
04:59.280 --> 05:03.130
is something that Ansible is going to expect. So when you happen to define a
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

114
04:59.280 --> 05:03.130
is something that Ansible is going to expect. So when you happen to define a

115
05:03.130 --> 05:04.560
particular file in

116
05:04.560 --> 05:08.690
this particular folder, when using a role, you don't actually have to give the

117
05:08.690 --> 05:09.680
absolute path to

118
05:09.680 --> 05:14.580
locate that particular file. And did instead, Ansible, like I say, is going to

119
05:14.580 --> 05:15.280
expect that

120
05:15.280 --> 05:19.020
file to be in that folder and it will automatically check for its existence

121
05:19.020 --> 05:20.080
there. So basically,

122
05:20.080 --> 05:23.620
you can just put the file in that particular folder and just reference the file

123
05:23.620 --> 05:24.400
name itself.

124
05:24.400 --> 05:28.230
Now the next one here is something called handlers. And we can see we actually

125
05:28.230 --> 05:29.840
have a main.YML

126
05:29.840 --> 05:33.600
file within that directory. Now we actually haven't talked about handlers quite
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

126
05:29.840 --> 05:33.600
file within that directory. Now we actually haven't talked about handlers quite

127
05:33.600 --> 05:34.000
just yet.

128
05:34.000 --> 05:38.140
We'll get to that in an upcoming skill. But as a high level overview, pretty

129
05:38.140 --> 05:38.400
much,

130
05:38.400 --> 05:42.890
it's a special type of Ansible task that will actually execute depending on the

131
05:42.890 --> 05:43.520
outcome of

132
05:43.520 --> 05:47.660
another Ansible task, basically when a particular condition has been met. Again

133
05:47.660 --> 05:48.240
, like I say,

134
05:48.240 --> 05:51.970
we'll get to look at those in more detail later on within this course. Then we

135
05:51.970 --> 05:52.880
come to the next

136
05:52.880 --> 05:57.130
directory, which is the meta directory. And again, inside of that particular

137
05:57.130 --> 05:58.160
file, we can see we

138
05:58.160 --> 06:03.260
have a main.YML. The purpose of this particular file is really well just to
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

138
05:58.160 --> 06:03.260
have a main.YML. The purpose of this particular file is really well just to

139
06:03.260 --> 06:05.040
specify the metadata

140
06:05.040 --> 06:08.440
associated with the role. So the type of thing that you would specify would be

141
06:08.440 --> 06:09.680
perhaps who actually

142
06:09.680 --> 06:13.200
authored the role, what was the date and which it was created, what type of

143
06:13.200 --> 06:14.000
licensing do you

144
06:14.000 --> 06:17.650
have for this particular role? Is it free for anyone to use? Maybe you want to

145
06:17.650 --> 06:18.160
specify the

146
06:18.160 --> 06:21.570
particular dependencies that have to be installed in order for the role to

147
06:21.570 --> 06:22.880
greatly operate. All of

148
06:22.880 --> 06:27.550
that you can define in that main.YML file within the meta directory. Now the

149
06:27.550 --> 06:27.920
next

150
06:27.920 --> 06:32.890
one we come to is the readme.md. This is a markdown file. Now if you happen to
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

150
06:27.920 --> 06:32.890
one we come to is the readme.md. This is a markdown file. Now if you happen to

151
06:32.890 --> 06:34.160
have experience with

152
06:34.160 --> 06:38.060
version control and something known as get or get up, you will probably

153
06:38.060 --> 06:39.360
recognize this particular

154
06:39.360 --> 06:43.830
file readme as a kind of instruction about how to use the particular utility.

155
06:43.830 --> 06:44.960
So in this case here,

156
06:44.960 --> 06:49.170
if you want to tell people how to actually use the role, what its purpose is,

157
06:49.170 --> 06:49.520
how they should

158
06:49.520 --> 06:53.730
modify particular values, as well as what they shouldn't use the role for, you

159
06:53.730 --> 06:54.800
would specify

160
06:54.800 --> 06:59.480
all of those instructions inside of the readme markdown file. Now the next one,

161
06:59.480 --> 07:00.240
this one is
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

161
06:59.480 --> 07:00.240
this one is

162
07:00.240 --> 07:04.760
probably very, very recognizable. This is the tasks folder and inside of the

163
07:04.760 --> 07:05.520
task folder,

164
07:05.520 --> 07:10.550
once again, we have a main.YML file. Now the purpose of this particular file,

165
07:10.550 --> 07:11.600
you guessed it.

166
07:11.600 --> 07:16.600
This is where you define the tasks that the role is going to perform. So really

167
07:16.600 --> 07:17.440
, this particular

168
07:17.440 --> 07:21.320
folder is very, very important. It's one of the core components of the Ansible

169
07:21.320 --> 07:22.160
role itself. We'll

170
07:22.160 --> 07:26.580
definitely get to see this later on within this particular skill. Next, we come

171
07:26.580 --> 07:27.440
to a directory

172
07:27.440 --> 07:31.520
known as templates. Now you might have a good idea what this one is all about.
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

172
07:27.440 --> 07:31.520
known as templates. Now you might have a good idea what this one is all about.

173
07:31.520 --> 07:32.400
We just discussed

174
07:32.400 --> 07:36.650
templates in the previous skill. This is where we could specify our Ginger 2

175
07:36.650 --> 07:37.600
templates, which

176
07:37.600 --> 07:41.500
would be used to effectively render configurations that we would like to push

177
07:41.500 --> 07:43.040
onto our target devices.

178
07:43.040 --> 07:47.890
So maybe you want to perhaps templatize your, oh I don't know, let's say, etsy

179
07:47.890 --> 07:48.800
resolve.conf

180
07:48.800 --> 07:52.190
configuration file, because imagine in this particular role, we're going to be

181
07:52.190 --> 07:53.120
doing some type of

182
07:53.120 --> 07:56.700
DNS config. Where are you going to put that particular template file? You're

183
07:56.700 --> 07:57.200
going to put it

184
07:57.200 --> 08:01.870
directly within this particular folder right here. Now one thing to note is
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

184
07:57.200 --> 08:01.870
directly within this particular folder right here. Now one thing to note is

185
08:01.870 --> 08:03.120
that if we happen to do

186
08:03.120 --> 08:07.250
an LS right now, notice we already have a templates directory here. That's a

187
08:07.250 --> 08:08.560
lowercase t. This is

188
08:08.560 --> 08:13.260
where we created our prior Ansible templates. Now when we happen to utilize a

189
08:13.260 --> 08:14.480
role called within a

190
08:14.480 --> 08:19.200
playbook, this is not the folder that the role is going to look into. The role

191
08:19.200 --> 08:20.400
is going to look into

192
08:20.400 --> 08:24.640
this particular one which is housed, like I said again inside of that top level

193
08:24.640 --> 08:25.760
directory, the name

194
08:25.760 --> 08:30.080
of the role itself. So just do not get that confused. The next thing we come to
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

194
08:25.760 --> 08:30.080
of the role itself. So just do not get that confused. The next thing we come to

195
08:30.080 --> 08:31.040
is the tests

196
08:31.040 --> 08:35.430
folder and inside of here, we can actually see we have two particular files.

197
08:35.430 --> 08:36.240
One is called

198
08:36.240 --> 08:40.970
inventory and the other one is called test.yml. Now this one might seem a

199
08:40.970 --> 08:42.560
little bit peculiar. Why

200
08:42.560 --> 08:46.380
do we have a file called inventory? After all, we already have an Ansible

201
08:46.380 --> 08:47.760
inventory defined.

202
08:47.760 --> 08:52.020
But the whole purpose of this particular folder here is to run tests. So inside

203
08:52.020 --> 08:53.280
of the test.yml

204
08:53.280 --> 08:57.520
file, this is where you would define all of your tests. But think about it. If

205
08:57.520 --> 08:58.480
you're going to be

206
08:58.480 --> 09:02.980
testing things out, is it a very smart idea to test out things that might
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

206
08:58.480 --> 09:02.980
testing things out, is it a very smart idea to test out things that might

207
09:02.980 --> 09:04.320
happen to break

208
09:04.320 --> 09:09.010
against your real live production network? The real servers that your entire

209
09:09.010 --> 09:10.000
workforce is

210
09:10.000 --> 09:14.840
relying upon? Absolutely not. So in this case here, we are providing a second

211
09:14.840 --> 09:16.240
inventory which is going

212
09:16.240 --> 09:20.440
to be comprised of a whole bunch of mock devices, pretty much maybe some

213
09:20.440 --> 09:22.080
virtual machines, whatever

214
09:22.080 --> 09:26.150
it may be, somewhere whereby we can safely test out these new conflicts as the

215
09:26.150 --> 09:27.200
configuration going

216
09:27.200 --> 09:31.670
to be rendered correctly, as the status of the service going to be as expected.
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

216
09:27.200 --> 09:31.670
to be rendered correctly, as the status of the service going to be as expected.

217
09:31.670 --> 09:32.240
The best way to

218
09:32.240 --> 09:36.910
test that out is against a test network. That is the whole purpose of that

219
09:36.910 --> 09:38.000
inventory file.

220
09:38.000 --> 09:41.620
And then lastly, we come to this varsity rate to the inside of here. Once again

221
09:41.620 --> 09:42.560
, we have a main

222
09:42.560 --> 09:46.910
dot yaml file. And this is really quite similar to the very first directory we

223
09:46.910 --> 09:48.080
talked about. The

224
09:48.080 --> 09:52.140
name itself is giving us a little bit of a hints. This is where we define our

225
09:52.140 --> 09:53.280
variable values. Now,

226
09:53.280 --> 09:58.480
the difference here is that this is where we should define our specific values,

227
09:58.480 --> 09:59.200
the values that we

228
09:59.200 --> 10:03.460
would like to use if the default values do not suffice. Basically, if you want
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

228
09:59.200 --> 10:03.460
would like to use if the default values do not suffice. Basically, if you want

229
10:03.460 --> 10:04.240
to override the

230
10:04.240 --> 10:09.180
defaults, we want to define those values inside of this particular file right

231
10:09.180 --> 10:10.000
here. And they will

232
10:10.000 --> 10:14.130
be treated with a higher priority by Ansible if there happens to be a conflict

233
10:14.130 --> 10:15.120
with anything in

234
10:15.120 --> 10:18.600
the defaults folder. So I know that was a lot of information to get to within

235
10:18.600 --> 10:19.440
this particular

236
10:19.440 --> 10:22.950
video. But really, that is everything that we have to know about the directory

237
10:22.950 --> 10:23.760
structure of the

238
10:23.760 --> 10:28.010
Ansible role. With that said, how about we begin creating our very first Ans

239
10:28.010 --> 10:29.200
ible role and well,

240
10:29.200 --> 10:31.760
that's what we're doing in the very next video.
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

240
10:29.200 --> 10:31.760
that's what we're doing in the very next video.
