WEBVTT

1
00:00.000 --> 00:03.680
Okay friends, so let's get hands on with Ansible.

2
00:03.680 --> 00:07.520
So the first component that we are going to talk about is that Ansible

3
00:07.520 --> 00:08.960
configuration file.

4
00:08.960 --> 00:13.360
So if you happen to search for Ansible configuration file, you can click this

5
00:13.360 --> 00:14.720
top link right here.

6
00:14.720 --> 00:20.800
And notice it says here that certain settings in Ansible are adjusted with this

7
00:20.800 --> 00:21.360
particular

8
00:21.360 --> 00:26.800
file Ansible.cfg. Now one thing to note, Ansible is going to seek to find this

9
00:26.800 --> 00:28.080
particular configuration

10
00:28.080 --> 00:32.500
file in a variety of different places, each with a greater priority than the
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

10
00:28.080 --> 00:32.500
file in a variety of different places, each with a greater priority than the

11
00:32.500 --> 00:33.120
other.

12
00:33.120 --> 00:36.880
Now it says here the pass where the configuration file is searched and listed

13
00:36.880 --> 00:37.680
as in the reference

14
00:37.680 --> 00:42.160
documentation. If we just click this link here, this here is effectively the

15
00:42.160 --> 00:43.600
locations and priority

16
00:43.600 --> 00:47.530
levels in which Ansible will look for this particular configuration file. So

17
00:47.530 --> 00:48.480
the first thing is that

18
00:48.480 --> 00:52.700
if you happen to set your own environment variable and point it to a particular

19
00:52.700 --> 00:53.440
location,

20
00:53.440 --> 00:57.280
this is the first and primary location where Ansible is going to seek to find

21
00:57.280 --> 00:58.080
this particular

22
00:58.080 --> 01:03.390
file. Now if you have not set this environment variable, the next place it's
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

22
00:58.080 --> 01:03.390
file. Now if you have not set this environment variable, the next place it's

23
01:03.390 --> 01:04.480
going to be checked

24
01:04.480 --> 01:09.360
is for a file called Ansible.cfg in the current directory. So whatever you

25
01:09.360 --> 01:10.320
happen to be running

26
01:10.320 --> 01:14.420
Ansible from, it's going to say hey, is there a file in the same directory

27
01:14.420 --> 01:15.520
right here called

28
01:15.520 --> 01:20.410
Ansible.cfg and if it is, then it's going to look to use the configuration

29
01:20.410 --> 01:21.680
specified within that

30
01:21.680 --> 01:26.720
particular file. Now if you do not have the Ansible configuration file within

31
01:26.720 --> 01:27.760
the current directory

32
01:27.760 --> 01:32.040
where Ansible happens to be running, the next location is going to be in the
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

32
01:27.760 --> 01:32.040
where Ansible happens to be running, the next location is going to be in the

33
01:32.040 --> 01:33.520
user's home directory.

34
01:33.520 --> 01:36.620
So we can see this via the tilde character, which we know is their home

35
01:36.620 --> 01:37.760
directory. Now if

36
01:37.760 --> 01:41.200
you've got a key now, you'll notice that we happen to have a dot before the

37
01:41.200 --> 01:41.920
word Ansible.

38
01:41.920 --> 01:45.680
Denoting that in this case here, this would actually be a hidden file. Now

39
01:45.680 --> 01:47.040
suppose you have not created

40
01:47.040 --> 01:51.110
any of these environment variables or the files in these particular directories

41
01:51.110 --> 01:52.400
, the general system

42
01:52.400 --> 01:56.330
way configuration file is going to be found in the exit directory and then into

43
01:56.330 --> 01:57.520
the Ansible folder

44
01:57.520 --> 02:02.260
and the file itself will simply be just called Ansible.cfg. That is the order
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

44
01:57.520 --> 02:02.260
and the file itself will simply be just called Ansible.cfg. That is the order

45
02:02.260 --> 02:03.120
of operation.

46
02:03.120 --> 02:06.660
Now in my case here, the practice that I tend to follow is just simply putting

47
02:06.660 --> 02:08.080
an Ansible.cfg

48
02:08.080 --> 02:12.720
file within the directory in which I am working. You can specify anything you

49
02:12.720 --> 02:13.440
so wish, but that

50
02:13.440 --> 02:16.740
is the practice that I am going to be following. If you don't use that

51
02:16.740 --> 02:17.920
particular practice,

52
02:17.920 --> 02:21.370
just at least understand the order of operations and where Ansible is going to

53
02:21.370 --> 02:22.320
look to find

54
02:22.320 --> 02:26.710
that particular config. Now if we search Ansible inventory, let's collect this

55
02:26.710 --> 02:27.360
link here.

56
02:27.360 --> 02:31.360
If we scroll on down, we can see some examples of Ansible inventories.
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

56
02:27.360 --> 02:31.360
If we scroll on down, we can see some examples of Ansible inventories.

57
02:31.360 --> 02:35.460
Here we happen to have what is known as an Ansible inventory in the I and I

58
02:35.460 --> 02:36.080
format.

59
02:36.080 --> 02:40.400
Now the way we construct this is we specify our group names in square brackets.

60
02:40.400 --> 02:40.720
So we have a

61
02:40.720 --> 02:45.020
group here called web servers and inside of the web servers just below, we

62
02:45.020 --> 02:46.000
specify the actual

63
02:46.000 --> 02:50.800
nodes which belong to that particular group. So food.example.com and bar.

64
02:50.800 --> 02:51.840
example.com,

65
02:51.840 --> 02:56.560
they happen to be web server devices and below we have to have a grouping of

66
02:56.560 --> 02:57.760
database servers,

67
02:57.760 --> 03:02.560
DB servers and the nodes belonging to that particular group is one.example.com,
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

67
02:57.760 --> 03:02.560
DB servers and the nodes belonging to that particular group is one.example.com,

68
03:02.560 --> 03:08.000
two.example.com and three.example.com. Now in my opinion, this happens to be

69
03:08.000 --> 03:09.200
the easier way to

70
03:09.200 --> 03:13.900
happen to construct your Ansible inventory just as really simple, doesn't cause

71
03:13.900 --> 03:14.560
any hassle.

72
03:14.560 --> 03:18.800
But ultimately, I would say it's best suited for simple inventories.

73
03:18.800 --> 03:22.240
If you just happen to have some groups, a few nodes belonging to those groups,

74
03:22.240 --> 03:25.840
then it is a very good way to structure your Ansible inventory.

75
03:25.840 --> 03:30.650
Below though, we can see the same type of information specified in the YAML
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

75
03:25.840 --> 03:30.650
Below though, we can see the same type of information specified in the YAML

76
03:30.650 --> 03:31.360
format.

77
03:31.360 --> 03:34.800
Now the interesting thing here is with respect to YAML, we have a lot of

78
03:34.800 --> 03:36.160
emphasis on indentation.

79
03:36.160 --> 03:39.930
We'll talk about that a lot more in an upcoming skill. But basically, the

80
03:39.930 --> 03:41.120
indentation is very,

81
03:41.120 --> 03:44.370
very important if you happen to get the indentation wrong. The way the

82
03:44.370 --> 03:45.920
information is ingested is

83
03:45.920 --> 03:49.570
going to be completely different and in fact, it can just be invalid and will

84
03:49.570 --> 03:50.720
not work. So in my

85
03:50.720 --> 03:55.210
opinion, this is a little bit more complex because an armor rose to follow is

86
03:55.210 --> 03:56.400
easier to get the syntax

87
03:56.400 --> 04:01.060
wrong. However, if you happen to have groups within groups, i.e. nested groups
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

87
03:56.400 --> 04:01.060
wrong. However, if you happen to have groups within groups, i.e. nested groups

88
04:01.060 --> 04:01.920
and a much more

89
04:01.920 --> 04:06.620
complex inventory, having that information represented in YAML format is

90
04:06.620 --> 04:07.280
actually a lot

91
04:07.280 --> 04:11.770
easier to look at visually because you can easily see via the indentation,

92
04:11.770 --> 04:12.720
which group belongs to

93
04:12.720 --> 04:17.310
which group and to quickly assess visually the order of the hierarchy. Now like

94
04:17.310 --> 04:17.840
I say, for error

95
04:17.840 --> 04:21.140
purposes, it's going to be really quite simple. So I'm just going to stick to

96
04:21.140 --> 04:22.320
the i and i format.

97
04:22.320 --> 04:26.060
But if you so wish, if you're more comfortable with YAML, then feel free to

98
04:26.060 --> 04:27.040
construct your

99
04:27.040 --> 04:31.170
inventory in that manner. So with that said, let's go and begin configuring our
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

99
04:27.040 --> 04:31.170
inventory in that manner. So with that said, let's go and begin configuring our

100
04:31.170 --> 04:31.680
Ansible

101
04:31.680 --> 04:36.190
configuration file once again, I'm going to specify mine within my working

102
04:36.190 --> 04:37.680
directory. So right now,

103
04:37.680 --> 04:41.450
I'm inside of the Ansible home directory for the Ansible user. If we do a

104
04:41.450 --> 04:42.560
listing, we can see we

105
04:42.560 --> 04:46.240
have no files or directories within here. So what I'm going to do is I'm going

106
04:46.240 --> 04:47.440
to create a particular

107
04:47.440 --> 04:51.830
file just called Ansible dot CFG. If I create that do a listing, now that file

108
04:51.830 --> 04:53.600
exists. But as we know,

109
04:53.600 --> 04:57.470
there is no content within that particular file, let's add to it. So I will

110
04:57.470 --> 04:58.320
just save them

111
04:58.320 --> 05:03.330
Ansible CFG. If I hit i for insert, I can go into insert mode. And similar to
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

111
04:58.320 --> 05:03.330
Ansible CFG. If I hit i for insert, I can go into insert mode. And similar to

112
05:03.330 --> 05:03.920
the Ansible

113
05:03.920 --> 05:07.060
inventory, this is also going to be written via the i and i format. So I'm

114
05:07.060 --> 05:08.320
going to say within my

115
05:08.320 --> 05:11.540
square brackets, I'm going to create my default group, which is going to

116
05:11.540 --> 05:12.720
effectively denote my

117
05:12.720 --> 05:16.670
default settings. Now the first directive I'm going to give is specifying where

118
05:16.670 --> 05:17.280
about my

119
05:17.280 --> 05:21.630
inventory can be located. Now by default, if you did not specify an inventory

120
05:21.630 --> 05:22.400
location,

121
05:22.400 --> 05:27.060
the default is going to be in the AC directory. And then within the Ansible

122
05:27.060 --> 05:28.000
directory, there

123
05:28.000 --> 05:32.880
should be a file called hosts. So if we don't specify here, Ansible will look
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

123
05:28.000 --> 05:32.880
should be a file called hosts. So if we don't specify here, Ansible will look

124
05:32.880 --> 05:33.920
to this particular

125
05:33.920 --> 05:38.370
file. But in order to keep things simple, I'm going to specify the Ansible, she

126
05:38.370 --> 05:38.800
looked within the

127
05:38.800 --> 05:43.120
current directory for a particular file called inventory dot i and i. Now I'm

128
05:43.120 --> 05:43.840
going to specify

129
05:43.840 --> 05:48.390
the directive for the remote user, this is basically going to be the username,

130
05:48.390 --> 05:49.120
the Ansible is going

131
05:49.120 --> 05:53.550
to use in order to access the remote machines. Now remember, we created a

132
05:53.550 --> 05:55.040
dedicated Ansible user

133
05:55.040 --> 05:58.410
account on the devices that we're going to manage. So right here, we're going

134
05:58.410 --> 05:59.520
to specify that Ansible

135
05:59.520 --> 06:03.290
should actually use that particular account when logging in. Now I'm going to
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

135
05:59.520 --> 06:03.290
should actually use that particular account when logging in. Now I'm going to

136
06:03.290 --> 06:04.480
say host key checking,

137
06:04.480 --> 06:07.920
we're going to specify that as false, we don't really care about key checking.

138
06:07.920 --> 06:08.320
And then I'm going

139
06:08.320 --> 06:12.670
to say deprecation warning pretty much very often, Ansible is going to give you

140
06:12.670 --> 06:13.520
warnings about

141
06:13.520 --> 06:16.500
modules and whatnot that happened to be outdated. We don't want to have to

142
06:16.500 --> 06:17.680
worry about that. So I'll

143
06:17.680 --> 06:21.190
just leave these warning messages set to false. So these are our default

144
06:21.190 --> 06:22.560
configurations. What I

145
06:22.560 --> 06:26.800
now want to do is to specify how Ansible can actually elevate privileges. You

146
06:26.800 --> 06:27.680
know the way you do when

147
06:27.680 --> 06:32.100
you happen to have a shell within a device, you can just say pseudo and then
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

147
06:27.680 --> 06:32.100
you happen to have a shell within a device, you can just say pseudo and then

148
06:32.100 --> 06:33.120
type in the super user

149
06:33.120 --> 06:37.570
password. That is how we could perform an administrative system wide task. In

150
06:37.570 --> 06:38.640
the case here, we want to

151
06:38.640 --> 06:42.070
tell Ansible how to do that. So I'm going to say with thin mind square brackets

152
06:42.070 --> 06:42.640
once again,

153
06:42.640 --> 06:47.100
privilege escalation, basically how we can escalate our privileges. What I'm

154
06:47.100 --> 06:48.560
going to say is become

155
06:48.560 --> 06:52.700
equals true, which means we are going to seek to become the root user. I will

156
06:52.700 --> 06:53.520
specify how we

157
06:53.520 --> 06:57.170
actually elevate our privileges by specifying the become method. And I'll say

158
06:57.170 --> 06:58.000
we do that via the

159
06:58.000 --> 07:02.240
pseudo commands. And then I'll say the become user is simply the root user. And
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

159
06:58.000 --> 07:02.240
pseudo commands. And then I'll say the become user is simply the root user. And

160
07:02.240 --> 07:03.680
I will say become

161
07:03.680 --> 07:07.650
ask pass. And I'll set that to the value false. We don't want to be asking for

162
07:07.650 --> 07:08.960
passwords after all.

163
07:08.960 --> 07:13.550
So what's that now done if I press escape and then colon wq to writing quit and

164
07:13.550 --> 07:14.800
then hit enter,

165
07:14.800 --> 07:18.960
we have now written this configuration file. Now as per the configuration file,

166
07:18.960 --> 07:19.840
we specified that

167
07:19.840 --> 07:23.680
there should be a file called inventory dot I and I within the same directory

168
07:23.680 --> 07:24.320
right now that

169
07:24.320 --> 07:28.230
doesn't exist. So let's just create it by saying touch inventory dot I and I,

170
07:28.230 --> 07:29.280
if I don't LS,

171
07:29.280 --> 07:33.600
now that file exists. And we want to actually specify the content of that file.
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

171
07:29.280 --> 07:33.600
now that file exists. And we want to actually specify the content of that file.

172
07:33.600 --> 07:34.240
So inside of

173
07:34.240 --> 07:38.810
here, we are once again going to be using the INI format. So the grouping I'm

174
07:38.810 --> 07:39.840
going to create

175
07:39.840 --> 07:42.690
as within square brackets, I'm just going to create a group called all which

176
07:42.690 --> 07:43.680
will specify

177
07:43.680 --> 07:48.230
all of my devices. Now we can just specify the IP addresses of these particular

178
07:48.230 --> 07:48.800
devices,

179
07:48.800 --> 07:54.280
such as 192, 168, 160, and then specify 134, which would be the blue box and

180
07:54.280 --> 07:55.360
then we can do the IP

181
07:55.360 --> 08:01.920
address of 192, 168, 160 dot 135 for the yellow box. But quite honestly, this
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

181
07:55.360 --> 08:01.920
address of 192, 168, 160 dot 135 for the yellow box. But quite honestly, this

182
08:01.920 --> 08:02.640
is a little bit

183
08:02.640 --> 08:07.170
clunky. We would rather have some type of name resolution. So before I actually

184
08:07.170 --> 08:07.760
do this,

185
08:07.760 --> 08:12.410
if I just press Q to quit, what I want to do is within my Etsy directory, so I

186
08:12.410 --> 08:12.960
'll say pseudo

187
08:12.960 --> 08:17.700
them, Etsy and going to the host file. This is where we can specify some static

188
08:17.700 --> 08:18.480
DNS mappings.

189
08:18.480 --> 08:24.960
So if I happen to say 192, 168, 160 dot 134, and if I just map that to the name

190
08:24.960 --> 08:26.160
example dot blue

191
08:26.160 --> 08:30.470
box dot com, and I'll give it a short name of blue box. And I'll also specify
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

191
08:26.160 --> 08:30.470
box dot com, and I'll give it a short name of blue box. And I'll also specify

192
08:30.470 --> 08:32.400
192, 168, 160,

193
08:32.400 --> 08:37.840
dot 135. And I'll also say example dot yellow box dot com and we can reference

194
08:37.840 --> 08:38.480
that as the

195
08:38.480 --> 08:42.310
short name yellow box. If I just happened to press right and correct to safety

196
08:42.310 --> 08:42.960
changes,

197
08:42.960 --> 08:47.610
if I now just try to ping blue box, notice within here, we happen to be getting

198
08:47.610 --> 08:48.080
the name

199
08:48.080 --> 08:53.980
resolution we happen to be picking 192, 168, 160 dot 134. So because of this,

200
08:53.980 --> 08:54.480
and by the way,

201
08:54.480 --> 08:58.310
just similarly to prove this, if I say ping yellow box, we ping the other

202
08:58.310 --> 08:59.680
address within the

203
08:59.680 --> 09:03.330
answerable inventory, I'm just going to reference these host names. So once
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

203
08:59.680 --> 09:03.330
answerable inventory, I'm just going to reference these host names. So once

204
09:03.330 --> 09:04.480
again, go back into the

205
09:04.480 --> 09:09.500
inventory, enter to the all group or specify we have a blue box and a yellow

206
09:09.500 --> 09:10.720
box. And if I so

207
09:10.720 --> 09:14.110
wished I could create more groups. Of course, we only have two devices, but

208
09:14.110 --> 09:15.040
imagine you happen

209
09:15.040 --> 09:19.040
to have 500 devices, maybe somewhere in the USA, I can say, okay, we have a USA

210
09:19.040 --> 09:19.440
group,

211
09:19.440 --> 09:23.580
and then list all devices that happen to be in the United States, like device

212
09:23.580 --> 09:24.480
one, device two,

213
09:24.480 --> 09:29.040
and then maybe we've got a group for the UK, maybe say, UK server, UK database,

214
09:29.040 --> 09:30.080
whatever it may be,
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

214
09:29.040 --> 09:30.080
whatever it may be,

215
09:30.080 --> 09:33.640
you can create as many groups as you so wish, but like I said, we only have two

216
09:33.640 --> 09:34.160
devices,

217
09:34.160 --> 09:38.030
and we can reference those devices just by specifying the keyword all. That is

218
09:38.030 --> 09:39.120
a group that houses

219
09:39.120 --> 09:42.660
both of these devices. So really simple inventory we have right here, let's

220
09:42.660 --> 09:43.840
press WQ to write

221
09:43.840 --> 09:47.650
and quits. So with these basic components up and running, what I now want to do

222
09:47.650 --> 09:48.400
is to ensure that

223
09:48.400 --> 09:52.210
answerable can actually reach those devices within the all group, that is the

224
09:52.210 --> 09:53.280
blue box and the yellow

225
09:53.280 --> 09:57.230
box. And the answerable is actually able to successfully communicate and

226
09:57.230 --> 09:58.480
authenticate with those

227
09:58.480 --> 10:02.110
devices because remember we're not actually using any passwords, we're relying
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

227
09:58.480 --> 10:02.110
devices because remember we're not actually using any passwords, we're relying

228
10:02.110 --> 10:03.680
on those SSH keys.

229
10:03.680 --> 10:07.970
So a simple test we can do is just simple say, answerable all to target the all

230
10:07.970 --> 10:08.400
group,

231
10:08.400 --> 10:13.330
and then I'll specify I want to use the module ping. If I hit answer, look at

232
10:13.330 --> 10:14.160
this right here,

233
10:14.160 --> 10:18.070
it says yellow box success, we're able to reach that device. And below here we

234
10:18.070 --> 10:19.200
have the blue box

235
10:19.200 --> 10:24.170
and also a success. With that now done, answerable is now operational, and it

236
10:24.170 --> 10:25.360
is now fully capable

237
10:25.360 --> 10:27.580
of automating our lab environments.
