WEBVTT

1
00:00.000 --> 00:04.440
So friends in the previous video we discussed the concepts of partitioning as

2
00:04.440 --> 00:05.240
well as some

3
00:05.240 --> 00:09.280
of the partitioning tools we can use, namely the part of utility.

4
00:09.280 --> 00:11.920
Let's now see how we can use this using Ansible.

5
00:11.920 --> 00:12.920
So where are we going to go?

6
00:12.920 --> 00:15.180
You guessed it, we're going to go to the big old fashioned Google machine and

7
00:15.180 --> 00:15.520
we're going

8
00:15.520 --> 00:18.680
to search for Ansible partition disk.

9
00:18.680 --> 00:22.340
Now, you'll notice at the very top we get this particular link here, it says

10
00:22.340 --> 00:24.000
community.general.partum

11
00:24.000 --> 00:25.000
module.

12
00:25.000 --> 00:29.190
If we click on this, we can see here from the fully qualified collection name,

13
00:29.190 --> 00:29.440
this is

14
00:29.440 --> 00:31.800
not a part of Ansible core.
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

14
00:29.440 --> 00:31.800
not a part of Ansible core.

15
00:31.800 --> 00:34.770
So we're going to have to install it with our good old faithful command, Ans

16
00:34.770 --> 00:35.360
ible Galaxy

17
00:35.360 --> 00:38.200
collection install and then specify the name of the collection.

18
00:38.200 --> 00:42.710
Now, if you have been following along from an earlier scale, we should already

19
00:42.710 --> 00:43.240
have this

20
00:43.240 --> 00:46.670
particular collection installed, but in the event that you have not, then just

21
00:46.670 --> 00:47.160
copy this

22
00:47.160 --> 00:52.530
command as such, go to your terminal window on the control machine and just hit

23
00:52.530 --> 00:53.240
enter.

24
00:53.240 --> 00:56.760
As we can see here, I already have this particular collection installed.

25
00:56.760 --> 01:00.400
Now, let's go back and look at the documentation here.
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

25
00:56.760 --> 01:00.400
Now, let's go back and look at the documentation here.

26
01:00.400 --> 01:04.080
So scrolling on down, we can see the brief synopsis of what this tool is going

27
01:04.080 --> 01:04.480
to do,

28
01:04.480 --> 01:05.840
but kind of know what it's going to do.

29
01:05.840 --> 01:09.930
But nevertheless, as it says here, it's going to allow us to configure a block

30
01:09.930 --> 01:11.000
device partition

31
01:11.000 --> 01:14.920
and it's going to do this using the part of command under the hoods.

32
01:14.920 --> 01:19.400
So check out, if we look at the parameters here, we're going to have some

33
01:19.400 --> 01:20.400
important ones

34
01:20.400 --> 01:22.640
here as one, which is very, very important.

35
01:22.640 --> 01:26.960
You can see here directly because what does it say it says it is required,

36
01:26.960 --> 01:27.520
meaning that

37
01:27.520 --> 01:31.720
the module itself will not work unless we supply this particular value.
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

37
01:27.520 --> 01:31.720
the module itself will not work unless we supply this particular value.

38
01:31.720 --> 01:34.800
Now, this happens to be the device parameter.

39
01:34.800 --> 01:38.790
We're going to supply a string value and that is simply going to be the block

40
01:38.790 --> 01:39.600
device that

41
01:39.600 --> 01:40.960
you want to target.

42
01:40.960 --> 01:44.350
So remember on the previous video, we happened to manually use the part of

43
01:44.350 --> 01:44.960
utility.

44
01:44.960 --> 01:52.440
We targeted a very particular device, which was dev/ and it was NVMe0n2.

45
01:52.440 --> 01:57.280
I believe pretty much in my case, this is the value that I would supply to this

46
01:57.280 --> 01:57.720
required

47
01:57.720 --> 01:58.720
parameter.

48
01:58.720 --> 02:01.880
Again, if you happen to have a different value, do not sweat it.
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

48
01:58.720 --> 02:01.880
Again, if you happen to have a different value, do not sweat it.

49
02:01.880 --> 02:04.640
Just provide the value on your particular system.

50
02:04.640 --> 02:07.600
Notice we have this option here, FS_type.

51
02:07.600 --> 02:11.680
This is pretty much where we can supply the type of file system that we want to

52
02:11.680 --> 02:12.160
give to

53
02:12.160 --> 02:13.760
this particular partition.

54
02:13.760 --> 02:18.200
So remember in the previous video where we happened to use the part of utility,

55
02:18.200 --> 02:18.400
in my

56
02:18.400 --> 02:23.480
case we can specify a particular value, the default I believe was EXD2.

57
02:23.480 --> 02:28.060
In my case, because it was a railway system, I chose to use XFS, but pretty

58
02:28.060 --> 02:28.760
much with

59
02:28.760 --> 02:34.300
Ansible by providing that particular value to this particular parameter, we can
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

59
02:28.760 --> 02:34.300
Ansible by providing that particular value to this particular parameter, we can

60
02:34.300 --> 02:34.720
do that

61
02:34.720 --> 02:37.960
particular operation this time using Ansible.

62
02:37.960 --> 02:41.120
Notice if we so wish we can specify a label to use.

63
02:41.120 --> 02:45.810
So again, going back to the previous video, we happened to supply the GPT style

64
02:45.810 --> 02:46.200
label

65
02:46.200 --> 02:47.200
to the partition.

66
02:47.200 --> 02:50.200
That would allow us to, in effect, create that GPT style partition.

67
02:50.200 --> 02:54.050
But if we so wish we could use, as it says here, the default value in this case

68
02:54.050 --> 02:54.400
here,

69
02:54.400 --> 02:55.560
MS_DOS.

70
02:55.560 --> 03:00.400
This is what we would use for MBR style partitions using the part of command.
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

70
02:55.560 --> 03:00.400
This is what we would use for MBR style partitions using the part of command.

71
03:00.400 --> 03:03.330
And if we happen to do so with Ansible, this is how we would invoke that

72
03:03.330 --> 03:04.400
particular behavior.

73
03:04.400 --> 03:07.200
Now this one here is your rather important parameter also.

74
03:07.200 --> 03:09.200
This is the number parameter.

75
03:09.200 --> 03:12.640
Notice this is going to take an integer value pretty much.

76
03:12.640 --> 03:16.640
This is the partition number that we want to specify.

77
03:16.640 --> 03:19.830
So in the case here, if we're just going to have one particular partition, we

78
03:19.830 --> 03:20.360
can specify

79
03:20.360 --> 03:21.960
partition number one.

80
03:21.960 --> 03:25.220
If we happen to have, let's maybe say three partitions, maybe we want to target

81
03:25.220 --> 03:25.760
the second

82
03:25.760 --> 03:29.950
partition or the third, whatever it may be, we specify that information via

83
03:29.950 --> 03:30.920
this particular
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

83
03:29.950 --> 03:30.920
this particular

84
03:30.920 --> 03:31.920
parameter.

85
03:31.920 --> 03:35.870
Important to note, by the way, is that this happens to be required when

86
03:35.870 --> 03:37.080
performing any

87
03:37.080 --> 03:40.640
action on the disk except for fetching information.

88
03:40.640 --> 03:43.950
So if you're going to be creating some brand new partition, you want to supply

89
03:43.950 --> 03:44.720
that partition

90
03:44.720 --> 03:45.720
number.

91
03:45.720 --> 03:47.800
Now this one here is also an important option.

92
03:47.800 --> 03:49.800
We have part_end.

93
03:49.800 --> 03:53.200
Again, we supply a string value.

94
03:53.200 --> 03:56.550
Now it says here, this is where the partition will end as offset from the

95
03:56.550 --> 03:57.400
beginning of the

96
03:57.400 --> 03:58.400
disk.

97
03:58.400 --> 04:01.840
Pretty much how big do we want the partition to be.
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

97
03:58.400 --> 04:01.840
Pretty much how big do we want the partition to be.

98
04:01.840 --> 04:03.640
Now we can do this in two different ways.

99
04:03.640 --> 04:07.110
We can specify that maybe we want to use in the case here as per the

100
04:07.110 --> 04:08.240
documentation.

101
04:08.240 --> 04:12.660
We would like the partition to end after 10 gig or just like we saw in the

102
04:12.660 --> 04:13.760
previous video,

103
04:13.760 --> 04:17.120
we can actually specify a percentage of the disk to use.

104
04:17.120 --> 04:21.200
And the previous example, we use 100% of the disk which utilized all of the

105
04:21.200 --> 04:22.160
disk of course.

106
04:22.160 --> 04:26.370
But in the example here as per the documentation, we can specify a number such

107
04:26.370 --> 04:27.120
as let's say

108
04:27.120 --> 04:32.400
15% or if you want 25% or 50% that type of thing.
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

108
04:27.120 --> 04:32.400
15% or if you want 25% or 50% that type of thing.

109
04:32.400 --> 04:35.990
Notice if you do not supply a particular value, the default value assumed is

110
04:35.990 --> 04:37.160
going to be 100%

111
04:37.160 --> 04:38.840
of the disk will be used.

112
04:38.840 --> 04:43.350
We also have the option of part_start which is pretty much the inversion of

113
04:43.350 --> 04:44.080
what we just

114
04:44.080 --> 04:45.080
saw before.

115
04:45.080 --> 04:48.080
This is where the partition offset is going to begin.

116
04:48.080 --> 04:52.580
Similarly, as we saw before, we can specify the value in gigabytes if we saw

117
04:52.580 --> 04:53.160
which or

118
04:53.160 --> 04:58.770
as a percentage noted to default value is 0% pretty much the beginning of the

119
04:58.770 --> 04:59.360
disk if

120
04:59.360 --> 05:01.240
we don't specify otherwise.
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

120
04:59.360 --> 05:01.240
we don't specify otherwise.

121
05:01.240 --> 05:03.960
We also have the state option right here.

122
05:03.960 --> 05:07.150
And this is how we actually decide if we want to create a partition or if we

123
05:07.150 --> 05:08.040
want to remove

124
05:08.040 --> 05:12.620
a partition, if we want to remove it, well, we can set the state to absent and

125
05:12.620 --> 05:13.440
that will

126
05:13.440 --> 05:17.410
specify the particular partition we have used via the device via the partition

127
05:17.410 --> 05:18.120
number and

128
05:18.120 --> 05:19.720
then simply remove it.

129
05:19.720 --> 05:24.500
However, if we want to create a partition, we set the value to be present which

130
05:24.500 --> 05:25.000
in our

131
05:25.000 --> 05:27.160
case here, this is what we're going to do.

132
05:27.160 --> 05:30.680
So these are just some of the available parameters as we can see in the
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

132
05:27.160 --> 05:30.680
So these are just some of the available parameters as we can see in the

133
05:30.680 --> 05:31.760
documentation.

134
05:31.760 --> 05:35.420
But as you know and can expect as always, there are more parameters and if you

135
05:35.420 --> 05:36.000
so wish,

136
05:36.000 --> 05:37.520
then you are free to explore them.

137
05:37.520 --> 05:41.240
But now that we have a decent grasp about what the options are, let's go and

138
05:41.240 --> 05:41.920
begin writing

139
05:41.920 --> 05:44.960
a playbook to actually automate this particular task.

140
05:44.960 --> 05:48.620
So let's go back to the control node and what I will do here is I will create a

141
05:48.620 --> 05:49.160
playbook

142
05:49.160 --> 05:50.160
called play1.yml.

143
05:50.160 --> 05:54.400
So the very first thing I will do is go into insert mode, I'll have my three

144
05:54.400 --> 05:55.080
hyphens at

145
05:55.080 --> 05:59.200
the top to denote my yaml file and I'll give this playbook a name simply called

146
05:59.200 --> 06:00.160
play1.
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

146
05:59.200 --> 06:00.160
play1.

147
06:00.160 --> 06:02.880
Create a partition using partition.

148
06:02.880 --> 06:07.200
Now this is where I want to specify which hosts in my inventory do I want to

149
06:07.200 --> 06:07.960
target.

150
06:07.960 --> 06:12.720
Now for a start, let me just say the host is going to be the blue box.

151
06:12.720 --> 06:16.440
After all that is where I added the new disk to be targeted.

152
06:16.440 --> 06:20.950
Now in this case here, what I will do here is I'll set gather facts to be false

153
06:20.950 --> 06:21.200
and now

154
06:21.200 --> 06:23.680
what I can do is begin defining my task.

155
06:23.680 --> 06:26.360
So the very first task is going to be called task1.

156
06:26.360 --> 06:27.880
Let's just say test task.

157
06:27.880 --> 06:28.880
Okay.

158
06:28.880 --> 06:32.300
At this point here, what I'm going to do is to provide the module that I want
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

158
06:28.880 --> 06:32.300
At this point here, what I'm going to do is to provide the module that I want

159
06:32.300 --> 06:32.800
to use.

160
06:32.800 --> 06:34.680
Now what is the module actually called?

161
06:34.680 --> 06:40.880
Well, the fully qualified collection name is community dot general dot parted.

162
06:40.880 --> 06:44.690
And now we're going to supply the particular parameters that we just saw within

163
06:44.690 --> 06:45.880
the documentation.

164
06:45.880 --> 06:50.720
So one particular parameter that is required is the device parameter case.

165
06:50.720 --> 06:53.080
We're going to make sure that is specified.

166
06:53.080 --> 06:55.160
What is it we want to target now?

167
06:55.160 --> 06:56.720
We're going to look at the blue box.

168
06:56.720 --> 07:02.800
And like I say, it's going to be this particular disk right here, dev nvm e0 n2
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

168
06:56.720 --> 07:02.800
And like I say, it's going to be this particular disk right here, dev nvm e0 n2

169
07:02.800 --> 07:03.880
once again,

170
07:03.880 --> 07:06.840
use the value as required on your own system.

171
07:06.840 --> 07:10.620
So all I will do is I will paste in that particular value right here and target

172
07:10.620 --> 07:11.720
that device.

173
07:11.720 --> 07:15.940
Now the next thing I'm going to do is I'm going to specify which partition

174
07:15.940 --> 07:16.520
number that

175
07:16.520 --> 07:17.880
I want to specify.

176
07:17.880 --> 07:21.830
So we use the number parameter and again, remember this is going to take an

177
07:21.830 --> 07:23.320
integer value.

178
07:23.320 --> 07:27.400
So in my case here, I want to target the first partition that is going to be

179
07:27.400 --> 07:28.040
the partition

180
07:28.040 --> 07:29.320
that I'm going to create.

181
07:29.320 --> 07:31.320
Now like I say, am I going to create it?
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

181
07:29.320 --> 07:31.320
Now like I say, am I going to create it?

182
07:31.320 --> 07:32.320
Am I going to delete it?

183
07:32.320 --> 07:35.440
Well, I can specify that via the state parameter.

184
07:35.440 --> 07:39.040
And in this case here, I'm going to state that the state should indeed be

185
07:39.040 --> 07:39.680
present.

186
07:39.680 --> 07:45.570
Now what I'm going to do here is specify when should the partition actually end

187
07:45.570 --> 07:46.280
now again,

188
07:46.280 --> 07:47.800
we can specify this in two ways.

189
07:47.800 --> 07:51.860
We can say this is going to end after one gig if I so wish but in my case here,

190
07:51.860 --> 07:52.120
I just

191
07:52.120 --> 07:55.770
like to do as a matter of percentage and I will just say it's going to end

192
07:55.770 --> 07:57.360
after 100%

193
07:57.360 --> 07:59.800
of the disk space has been used.

194
07:59.800 --> 08:00.800
So check this out.
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

194
07:59.800 --> 08:00.800
So check this out.

195
08:00.800 --> 08:04.800
So what I will do here is I'll press escape colon wq to write and quits.

196
08:04.800 --> 08:08.680
I will just ping my blue box to make sure I have connectivity, which I do.

197
08:08.680 --> 08:12.200
And with that now done, all I'm going to do here is say answerable playbook

198
08:12.200 --> 08:12.760
play one

199
08:12.760 --> 08:14.880
dot yml and to enter.

200
08:14.880 --> 08:18.960
And as we can see here, we do have a change on the system.

201
08:18.960 --> 08:22.040
So with that now done, if I go back to my blue box.

202
08:22.040 --> 08:25.900
If I now arrow up and run the part of the list command once again, type in my

203
08:25.900 --> 08:26.520
password

204
08:26.520 --> 08:27.960
for the super user.

205
08:27.960 --> 08:30.920
Now we can actually see here we have these values populated.
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

205
08:27.960 --> 08:30.920
Now we can actually see here we have these values populated.

206
08:30.920 --> 08:33.560
We have partition number one as we specified.

207
08:33.560 --> 08:37.710
We have a primary partition and we can see the size of the partition is we have

208
08:37.710 --> 08:38.080
used the

209
08:38.080 --> 08:42.400
desk and its entirety 100% of that particular disk.

210
08:42.400 --> 08:44.240
Now let me just show you something here.

211
08:44.240 --> 08:49.220
Let's just say I wanted to run this particular command against both of my

212
08:49.220 --> 08:50.160
devices.

213
08:50.160 --> 08:53.300
Now what I'm going to do here is I'm going to delete that particular change

214
08:53.300 --> 08:53.800
right now

215
08:53.800 --> 08:54.800
just to undo it.

216
08:54.800 --> 08:59.240
So I'll say pseudo part of dev nvm e0n2 to target that particular device.

217
08:59.240 --> 09:03.800
And I'm going to say Rm1 to remove the partition and then select quits.
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

217
08:59.240 --> 09:03.800
And I'm going to say Rm1 to remove the partition and then select quits.

218
09:03.800 --> 09:07.880
If I relist, now we can see here all of that information is now cleared.

219
09:07.880 --> 09:08.880
Check this out then.

220
09:08.880 --> 09:13.480
If I go back to my actual playbook here and all I'm going to do here is let me

221
09:13.480 --> 09:14.160
just copy

222
09:14.160 --> 09:17.400
this over and I'll create this one call play two dot yml.

223
09:17.400 --> 09:21.810
I think when you play two and I go into insert mode and I change the hosts to

224
09:21.810 --> 09:22.520
actually be

225
09:22.520 --> 09:23.520
the all group.

226
09:23.520 --> 09:27.280
Now what do you actually think the problem might be here?

227
09:27.280 --> 09:33.500
Well, if you can remember we have indeed created this particular disk here on
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

227
09:27.280 --> 09:33.500
Well, if you can remember we have indeed created this particular disk here on

228
09:33.500 --> 09:34.200
our blue

229
09:34.200 --> 09:39.540
box but it doesn't actually exist on the yellow box which is now as per the all

230
09:39.540 --> 09:40.600
instruction

231
09:40.600 --> 09:42.280
also going to be targeted.

232
09:42.280 --> 09:44.960
So we're going to run into a little bit of an error here.

233
09:44.960 --> 09:46.960
We're going to see how we're going to handle that.

234
09:46.960 --> 09:47.960
So I'll just write quits.

235
09:47.960 --> 09:51.640
So let's try to run playbook number two this time and to enter.

236
09:51.640 --> 09:56.250
And we can see here we have a change on the blue box but we also actually have

237
09:56.250 --> 09:57.160
this failure

238
09:57.160 --> 09:58.160
right here.

239
09:58.160 --> 10:01.080
Now check this out from the output here it says Ansible Facts.
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

239
09:58.160 --> 10:01.080
Now check this out from the output here it says Ansible Facts.

240
10:01.080 --> 10:02.080
Error.

241
10:02.080 --> 10:07.880
There was not a device called dev nvm e0n2 on that particular system.

242
10:07.880 --> 10:09.360
So think about it like this.

243
10:09.360 --> 10:14.190
We have this playbook that we only want to execute against this particular

244
10:14.190 --> 10:14.760
device.

245
10:14.760 --> 10:19.920
If that device actually exists how then are we going to solve this particular

246
10:19.920 --> 10:20.960
problem?

247
10:20.960 --> 10:25.220
Well we know from previous scales we can actually invoke conditional logic to

248
10:25.220 --> 10:25.680
do such

249
10:25.680 --> 10:26.680
a thing.

250
10:26.680 --> 10:30.150
So the challenge for us right now is to determine how do we know if a
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

250
10:26.680 --> 10:30.150
So the challenge for us right now is to determine how do we know if a

251
10:30.150 --> 10:31.880
particular system has this

252
10:31.880 --> 10:33.760
particular device available to it?

253
10:33.760 --> 10:35.160
Well, let's find out.

254
10:35.160 --> 10:38.040
So what I'm going to do here is I'm going to invoke Ansible directly from the

255
10:38.040 --> 10:38.200
command

256
10:38.200 --> 10:41.080
line and I'm going to target the blue box.

257
10:41.080 --> 10:45.490
We know that particular device exists on that box and the module I want to use

258
10:45.490 --> 10:46.040
is going

259
10:46.040 --> 10:48.520
to be the Ansible built in setup module.

260
10:48.520 --> 10:52.230
If I just hit enter and give it a moment it's going to collect the facts about

261
10:52.230 --> 10:53.040
this particular

262
10:53.040 --> 10:55.040
device and then we'll examine the output.

263
10:55.040 --> 10:57.600
Okay, so we get all the information back right here.

264
10:57.600 --> 10:58.600
Okay.

265
10:58.600 --> 11:01.690
Now if we scroll on up to the very top right now we can see here we have this
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

265
10:58.600 --> 11:01.690
Now if we scroll on up to the very top right now we can see here we have this

266
11:01.690 --> 11:02.240
outer key

267
11:02.240 --> 11:06.720
Ansible underscore facts and everything else is going to be nested within.

268
11:06.720 --> 11:10.790
Now we see all these other keys such as Ansible all IPv4 addresses and that

269
11:10.790 --> 11:12.000
lists the IPv4

270
11:12.000 --> 11:13.600
addresses, that type of thing.

271
11:13.600 --> 11:17.720
What we want to do is to find the key that is going to find information about

272
11:17.720 --> 11:18.480
the devices

273
11:18.480 --> 11:20.840
attached to that particular system.

274
11:20.840 --> 11:23.800
So the actual key we're going to look for is the devices key.

275
11:23.800 --> 11:25.680
So let's just scroll down a little bit here.

276
11:25.680 --> 11:29.010
To check out this part here Ansible devices, this shows us all the attached

277
11:29.010 --> 11:29.640
devices.

278
11:29.640 --> 11:32.880
So let's go to the next keys within, scroll on down.
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

278
11:29.640 --> 11:32.880
So let's go to the next keys within, scroll on down.

279
11:32.880 --> 11:36.320
Next we actually have keys here correlating to the device themselves.

280
11:36.320 --> 11:39.680
In this case here we have NVMe 0n1.

281
11:39.680 --> 11:43.720
The one we want to see is the presence of NVMe 0n2.

282
11:43.720 --> 11:47.560
Now if I scroll on down here, check this out right here.

283
11:47.560 --> 11:50.280
This does actually exist on the blue box.

284
11:50.280 --> 11:54.170
So in fact what I could do is if I want to take that output and just grab it

285
11:54.170 --> 11:54.800
for NVMe

286
11:54.800 --> 11:59.490
0n2 and to enter, we can see here we're actually getting output for that

287
11:59.490 --> 12:00.520
particular device to
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

287
11:59.490 --> 12:00.520
particular device to

288
12:00.520 --> 12:03.970
the blue box whereas if I scroll on up and I try to create for the same

289
12:03.970 --> 12:04.880
information on

290
12:04.880 --> 12:08.200
the yellow box, well this is not going to be present and that is actually the

291
12:08.200 --> 12:08.680
problem

292
12:08.680 --> 12:09.680
we're experiencing.

293
12:09.680 --> 12:12.960
And we can see the module runs and we have no output shown.

294
12:12.960 --> 12:16.210
So really what we want to do is we want to go into our playbook here and we're

295
12:16.210 --> 12:16.560
going

296
12:16.560 --> 12:18.080
to add that conditional statement.

297
12:18.080 --> 12:22.090
So remember at the same level of indentation as the actual module we want to

298
12:22.090 --> 12:22.760
use here,

299
12:22.760 --> 12:24.480
we will have the when keyword.

300
12:24.480 --> 12:26.280
Now what is it we're going to target here?

301
12:26.280 --> 12:28.920
Well I'm going to say Ansible_Facts.

302
12:28.920 --> 12:31.920
Now I want to parse out the particular keys that I'm looking for.
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

302
12:28.920 --> 12:31.920
Now I want to parse out the particular keys that I'm looking for.

303
12:31.920 --> 12:38.750
So I will say Ansible_Devices and then the key within is going to be the NVMe

304
12:38.750 --> 12:41.400
key 0n2

305
12:41.400 --> 12:45.480
and I want to add the condition that that key is defined in the output.

306
12:45.480 --> 12:50.260
So if we happen to find this particular key in the presence of the Ansible_F

307
12:50.260 --> 12:51.960
acts, then

308
12:51.960 --> 12:55.700
this particular command, this particular module should I say is going to

309
12:55.700 --> 12:56.360
operate.

310
12:56.360 --> 13:01.050
However in the case of any host whereby this particular line of keys is not
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

310
12:56.360 --> 13:01.050
However in the case of any host whereby this particular line of keys is not

311
13:01.050 --> 13:01.640
present,

312
13:01.640 --> 13:06.160
I eat on the yellow box, this part here is not going to execute.

313
13:06.160 --> 13:09.360
So one thing I'm going to have to do here is the fact that I'm relying on Ans

314
13:09.360 --> 13:09.920
ible_Facts,

315
13:09.920 --> 13:12.120
I actually want to make sure that we're gathering them.

316
13:12.120 --> 13:15.000
So what I will do here is I'll go up to the top and I'm going to remove the

317
13:15.000 --> 13:16.760
gather_Facts=false

318
13:16.760 --> 13:18.760
and make sure we're actually going to collect them.

319
13:18.760 --> 13:20.360
So let's check this out right here.

320
13:20.360 --> 13:23.730
Now on my blue box once again, I'm just going to go into Parted and I'm just

321
13:23.730 --> 13:23.880
going

322
13:23.880 --> 13:28.040
to say RM1 to remove that partition and if I list it once again, now the

323
13:28.040 --> 13:28.680
partition has

324
13:28.680 --> 13:29.680
been cleared.

325
13:29.680 --> 13:30.680
Now check this out.
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

325
13:29.680 --> 13:30.680
Now check this out.

326
13:30.680 --> 13:35.620
If I say Ansible_Playbook, play 2.YML and to enter now, we'll gather facts

327
13:35.620 --> 13:36.000
about the

328
13:36.000 --> 13:39.680
machines and then run our conditional statement to determine whether we should

329
13:39.680 --> 13:40.400
use the module

330
13:40.400 --> 13:42.520
against that particular device or not.

331
13:42.520 --> 13:45.320
So check this out, this might be a little bit unexpected here.

332
13:45.320 --> 13:49.600
It says here we are apparently skipping both the blue box and the yellow box.

333
13:49.600 --> 13:50.760
That doesn't really make sense.

334
13:50.760 --> 13:54.840
So as we would expect it to target the blue box but skip the yellow box.

335
13:54.840 --> 13:57.640
Now the reason being is a little bit of a peculiarity.

336
13:57.640 --> 14:01.650
When we happen to use the Ansible setup module as we did via the command line
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

336
13:57.640 --> 14:01.650
When we happen to use the Ansible setup module as we did via the command line

337
14:01.650 --> 14:02.600
right there,

338
14:02.600 --> 14:08.000
the keys nested within Ansible_Facts are all going to be prepended with the

339
14:08.000 --> 14:08.720
keyword

340
14:08.720 --> 14:09.720
Ansible_.

341
14:09.720 --> 14:14.410
So that means all the nested keys such as the key representing the devices in

342
14:14.410 --> 14:14.960
the output

343
14:14.960 --> 14:19.560
that we just saw actually say Ansible_Devices.

344
14:19.560 --> 14:23.970
However, when we want to access this particular key within our playbook, we

345
14:23.970 --> 14:25.240
just specify the

346
14:25.240 --> 14:26.240
keyword devices.

347
14:26.240 --> 14:30.080
We don't actually add on this Ansible_ Is that a little bit confusing?
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

347
14:26.240 --> 14:30.080
We don't actually add on this Ansible_ Is that a little bit confusing?

348
14:30.080 --> 14:31.320
Is that a little bit annoying?

349
14:31.320 --> 14:34.200
Yeah, kind of but that definitely is the way we've got to work.

350
14:34.200 --> 14:37.680
So with that said, let's make the necessary modification.

351
14:37.680 --> 14:40.040
So let's go into the playbook once again.

352
14:40.040 --> 14:44.450
And like I say, when it comes to the keys inside, all we want to do is remove

353
14:44.450 --> 14:45.640
Ansible_HeroCare.

354
14:45.640 --> 14:49.080
So now we should actually correct the target, these particular keys.

355
14:49.080 --> 14:52.720
So let's save this and we will rerun the playbook once again.

356
14:52.720 --> 14:56.200
So let's hit enter, give it a moment, we'll gather the facts.

357
14:56.200 --> 14:59.240
And as we can see here, we have a little bit of a different outcome.

358
14:59.240 --> 15:03.150
The outcome that we actually hope for unexpected, we have made a change on the
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

358
14:59.240 --> 15:03.150
The outcome that we actually hope for unexpected, we have made a change on the

359
15:03.150 --> 15:04.080
blue box because

360
15:04.080 --> 15:08.160
we actually have the presence of the dev NVMe0N2 device.

361
15:08.160 --> 15:12.350
Whereas on the case of the yellow box, as opposed to having some type of fatal

362
15:12.350 --> 15:13.040
error,

363
15:13.040 --> 15:17.060
we are just simply skipping that box and not attempting to use that module on

364
15:17.060 --> 15:17.760
that particular
