WEBVTT

1
00:00.000 --> 00:02.640
So friends, let's walk through the validation solution.

2
00:02.640 --> 00:05.760
So the very first time we're going to have to do is to create a playbook called

3
00:05.760 --> 00:06.960
validation.yml.

4
00:06.960 --> 00:09.760
So let's start with that. So let's create this hit enter.

5
00:09.760 --> 00:12.480
Let's go into insert mode, have our three hyphens at the top.

6
00:12.480 --> 00:15.520
And the first place should only target one of your managed nodes.

7
00:15.520 --> 00:18.400
So in my case here, I will just target my blue box device.

8
00:18.400 --> 00:20.320
I'll set gather facts to be false.

9
00:20.320 --> 00:23.120
Now what I should attempt to do here is to create a directory called forward

10
00:23.120 --> 00:23.920
slash TMP

11
00:23.920 --> 00:26.880
forward slash validation and handle any errors.

12
00:26.880 --> 00:30.160
So let me define my tasks right here and the very first time I'm going to have
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

12
00:26.880 --> 00:30.160
So let me define my tasks right here and the very first time I'm going to have

13
00:30.160 --> 00:30.720
to do it to

14
00:30.720 --> 00:34.510
define my block keywords. So inside of here, sort of say, create the validation

15
00:34.510 --> 00:35.040
directory

16
00:35.040 --> 00:38.400
and I will use the Ansible built in file module, which we've seen before,

17
00:38.400 --> 00:41.770
or specify the path that I want to target is going to be forward slash TMP

18
00:41.770 --> 00:43.680
forward slash validation.

19
00:43.680 --> 00:46.720
Okay, then the state is going to be a directory.

20
00:46.720 --> 00:50.470
And now at the same level of indentation, I want to have my rescue message,

21
00:50.470 --> 00:50.960
sort of say,

22
00:50.960 --> 00:54.580
print custom error message. So now I want to do is to use my Ansible built in

23
00:54.580 --> 00:55.600
debug module.

24
00:55.600 --> 01:00.160
And the message is simply going to be error creating the validation there.
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

24
00:55.600 --> 01:00.160
And the message is simply going to be error creating the validation there.

25
01:00.160 --> 01:03.960
Now, regardless of whether or not we have a diverse success, we always want to

26
01:03.960 --> 01:04.320
run my

27
01:04.320 --> 01:07.700
particular commands. So the name here will just be simply a long list of

28
01:07.700 --> 01:09.120
contents of the temp

29
01:09.120 --> 01:13.200
directory. And I'll use the Ansible built in shell module. And I'll just say,

30
01:13.200 --> 01:18.420
LS dash L against TMP. Now, in order to actually see the output here, I want to

31
01:18.420 --> 01:19.360
register this.

32
01:19.360 --> 01:22.400
So I'll register this as a variable, which is called as list output.

33
01:22.400 --> 01:26.010
And now I'll have another task, which is going to be print the outputs. So

34
01:26.010 --> 01:26.320
again,

35
01:26.320 --> 01:29.740
I'll use the Ansible built in debug module. And this time here, I'll print at

36
01:29.740 --> 01:30.880
the variable list
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

36
01:29.740 --> 01:30.880
the variable list

37
01:30.880 --> 01:35.260
outputs. Okay, so what I want to do now is to create a second play. So again, I

38
01:35.260 --> 01:35.840
got all the way

39
01:35.840 --> 01:39.700
to the margin once again, I'll just do dash name to give it a name. I'll just

40
01:39.700 --> 01:41.280
call this play too.

41
01:41.280 --> 01:45.560
Now this time, I should be targeting everyone in my inventory, i.e. the all

42
01:45.560 --> 01:46.320
group. And what I'm

43
01:46.320 --> 01:49.570
going to do here is to find my tasks. So the first task is going to have a name

44
01:49.570 --> 01:50.320
. I'm just going to

45
01:50.320 --> 01:54.830
say copy fails to target. So this time, I will use the Ansible built in copy

46
01:54.830 --> 01:56.000
module. So specify

47
01:56.000 --> 02:00.130
the SRC, which is going to be home Ansible. And the first file will be
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

47
01:56.000 --> 02:00.130
the SRC, which is going to be home Ansible. And the first file will be

48
02:00.130 --> 02:01.520
validation 1.txt.

49
02:01.520 --> 02:04.880
I'm still going to have to create this on my own machine. And now I specify the

50
02:04.880 --> 02:05.760
destination.

51
02:05.760 --> 02:09.700
I will just put in the home directory of the nugget user, but again, choose any

52
02:09.700 --> 02:10.160
directory

53
02:10.160 --> 02:14.200
used to wish on your machine. And again, it's going to be called validation 1.

54
02:14.200 --> 02:15.040
txt. Now, if you

55
02:15.040 --> 02:18.270
so wish, what you could do is build this module with a particular loop, but in

56
02:18.270 --> 02:18.800
the interest of

57
02:18.800 --> 02:22.080
keeping things nice and simple, let's just do another task. And let's maybe

58
02:22.080 --> 02:23.040
just change this,

59
02:23.040 --> 02:28.290
copy fail 1 to target. And let's have a second task, just say copy fail 2.

60
02:28.290 --> 02:29.040
Again, let's specify

61
02:29.040 --> 02:34.240
the source. This one will be validation 2.txt and the destination forward slash
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

61
02:29.040 --> 02:34.240
the source. This one will be validation 2.txt and the destination forward slash

62
02:34.240 --> 02:35.360
home forward slash

63
02:35.360 --> 02:40.560
nugget user, and then validation 2.txt. So once these fails happen to be copied

64
02:40.560 --> 02:40.960
over,

65
02:40.960 --> 02:44.490
what we now want to do is to create an archive of these fails using the bzip2

66
02:44.490 --> 02:45.280
compression.

67
02:45.280 --> 02:48.930
So let's create a new task, just to create a compressed archive. This time, a

68
02:48.930 --> 02:49.520
user community

69
02:49.520 --> 02:53.020
general archive module, so we'll specify the path. So in this case, here, it's

70
02:53.020 --> 02:53.680
going to be the

71
02:53.680 --> 02:57.680
forward slash home nugget user directory. And then what I want to do is I want

72
02:57.680 --> 02:58.400
to use fail

73
02:58.400 --> 03:03.540
globing. So I'll say validation, and then a question mark dot txt. So that will
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

73
02:58.400 --> 03:03.540
globing. So I'll say validation, and then a question mark dot txt. So that will

74
03:03.540 --> 03:05.520
include validation 1.txt

75
03:05.520 --> 03:09.680
as well as validation 2.txt. And now I want to specify the destination where

76
03:09.680 --> 03:10.480
this archive is

77
03:10.480 --> 03:13.930
going to be kept. And you can specify any destination user wish. Let's put this

78
03:13.930 --> 03:15.200
in the temp directory.

79
03:15.200 --> 03:22.180
And let's just call this validation archive dot tar dot bz2. Now the format is

80
03:22.180 --> 03:23.040
going to be

81
03:23.040 --> 03:27.110
bz2 compression. And that should be pretty much it. What we have to do though

82
03:27.110 --> 03:28.080
is to create these

83
03:28.080 --> 03:31.740
particular files validation 1 and validation 2 within the answerable home
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

83
03:28.080 --> 03:31.740
particular files validation 1 and validation 2 within the answerable home

84
03:31.740 --> 03:32.640
directory here on

85
03:32.640 --> 03:36.140
the control node. So like I say within this particular directory, I'll create

86
03:36.140 --> 03:38.720
fail call validation 1.txt.

87
03:38.720 --> 03:43.920
Going to insert more than say this is validation 1 and also create validation 2

88
03:43.920 --> 03:44.960
.txt. And just

89
03:44.960 --> 03:48.700
say this is validation number two. So let's just save here. And let's try to

90
03:48.700 --> 03:49.840
run the validation

91
03:49.840 --> 03:54.070
playbook. So let's hit enter play one executes. And now the second play

92
03:54.070 --> 03:55.440
executes. So let's check

93
03:55.440 --> 03:58.470
the actual results here. And let's just scroll up a little bit to ensure that

94
03:58.470 --> 03:59.360
we actually got the

95
03:59.360 --> 04:02.880
output over LS command, which we did right here. See this right here. Now the
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

95
03:59.360 --> 04:02.880
output over LS command, which we did right here. See this right here. Now the

96
04:02.880 --> 04:04.160
output here is not

97
04:04.160 --> 04:07.100
really the pretty is what I should actually have done is if I go back in, as I

98
04:07.100 --> 04:07.680
should actually

99
04:07.680 --> 04:11.010
have printed just the A to the out lines attributes, that would make it a

100
04:11.010 --> 04:12.640
little bit prettier. But

101
04:12.640 --> 04:15.460
nevertheless, we do see the presence of this validation directory. And we can

102
04:15.460 --> 04:16.480
see it's a directory

103
04:16.480 --> 04:20.160
because we have this de-present in the output. And if we go actually to the

104
04:20.160 --> 04:21.120
blue box right here

105
04:21.120 --> 04:25.050
and we do see the into validation, we can indeed see here, we do actually have

106
04:25.050 --> 04:25.920
a directory. Now

107
04:25.920 --> 04:29.600
effectively in both devices, we send the temp directory, we should also have

108
04:29.600 --> 04:30.720
this archive file
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

108
04:29.600 --> 04:30.720
this archive file

109
04:30.720 --> 04:35.490
validation, haven't archive dot tar dot bz2. So let's go to the blue box, go

110
04:35.490 --> 04:36.560
back a directory.

111
04:36.560 --> 04:41.580
Let's do an LS. There we can see we have our validation archive dot tar dot bz2

112
04:41.580 --> 04:42.000
. And on the

113
04:42.000 --> 04:45.670
yellow box, if we go into the 10th directory and doing LS, we can also see we

114
04:45.670 --> 04:46.800
have our validation

115
04:46.800 --> 04:52.370
archive dot tar dot bz2. And if it happens to tar dot x, lowercase j on the

116
04:52.370 --> 04:53.840
file of validation

117
04:53.840 --> 04:58.520
archive and enter, if I do an LS, we actually see the contents here are the

118
04:58.520 --> 04:59.680
correct text fails

119
04:59.680 --> 05:03.120
validation one and validation two. And again, if I happen to open these via the
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

119
04:59.680 --> 05:03.120
validation one and validation two. And again, if I happen to open these via the

120
05:03.120 --> 05:03.840
cat command,

121
05:03.840 --> 05:08.150
there is the content and there is a content and the same thing is true over on

122
05:08.150 --> 05:09.040
the blue box. Now

123
05:09.040 --> 05:12.390
one thing I want to show you here is just to ensure that our blog is actually

124
05:12.390 --> 05:13.600
working correctly.

125
05:13.600 --> 05:17.120
So notice on the blue box, we actually have this validation directory we've

126
05:17.120 --> 05:17.920
just created. What I

127
05:17.920 --> 05:22.090
will do here is I'll just delete it. Okay. So it no longer exists. What I will

128
05:22.090 --> 05:22.720
do though,

129
05:22.720 --> 05:26.340
is I'm going to actually create a file just called validation. So now we have

130
05:26.340 --> 05:27.040
this one here,

131
05:27.040 --> 05:30.940
but as we can see, it's not actually directory. It's just a regular file. So
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

131
05:27.040 --> 05:30.940
but as we can see, it's not actually directory. It's just a regular file. So

132
05:30.940 --> 05:31.600
what this means is

133
05:31.600 --> 05:35.020
that when the system goes to try to recreate this directory, it's going to

134
05:35.020 --> 05:36.000
encounter an error

135
05:36.000 --> 05:40.590
because we have a conflict between a file name and the directory name we're

136
05:40.590 --> 05:41.840
trying to create.

137
05:41.840 --> 05:45.600
This should provoke an error. And we want to see if we handle that error. So

138
05:45.600 --> 05:46.640
let's go for it then.

139
05:46.640 --> 05:50.620
So let's clear the screen. We'll say Ansible playbook validation dot yml. And

140
05:50.620 --> 05:51.360
to enter. Okay.

141
05:51.360 --> 05:54.730
So notice we don't actually have to copy any files or create a new compressed

142
05:54.730 --> 05:55.440
archive that

143
05:55.440 --> 05:59.360
already exists on the target. However, if we scroll on up, this is where the

144
05:59.360 --> 06:00.240
interesting bit is.
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

144
05:59.360 --> 06:00.240
interesting bit is.

145
06:00.240 --> 06:03.510
Look at this right here. We have an error trying to create our validation

146
06:03.510 --> 06:04.080
directory.

147
06:04.080 --> 06:07.410
However, we can see here we have successfully handled that error. And we are

148
06:07.410 --> 06:08.000
printing out the

149
06:08.000 --> 06:11.460
custom error message. Now what we're going to do is we're going to list the

150
06:11.460 --> 06:12.800
contents of the TMP

151
06:12.800 --> 06:17.380
directory, which we can see right here. And as we can see here, the validation

152
06:17.380 --> 06:18.880
file here is not

153
06:18.880 --> 06:23.100
actually a directory. So crucially, like you can see the playbook continued to

154
06:23.100 --> 06:24.000
execute despite

155
06:24.000 --> 06:28.000
that initial failure. So that is us for a validation challenge. I hope it's

156
06:28.000 --> 06:29.040
been informative for you.

157
06:29.040 --> 06:30.580
I'd like to thank you for viewing.
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

157
06:29.040 --> 06:30.580
I'd like to thank you for viewing.
