WEBVTT

1
00:00.000 --> 00:04.320
Now in this particular video, what I want to do is to turn your attention to

2
00:04.320 --> 00:07.500
some task scheduling options that we have available to us.

3
00:07.500 --> 00:11.460
So right now we are using the Ansible Automation system, so we obviously know

4
00:11.460 --> 00:13.400
the automation is a quite good thing.

5
00:13.400 --> 00:17.990
And one of the benefits of automation is that while we cut out things such as

6
00:17.990 --> 00:18.800
human error,

7
00:18.800 --> 00:21.900
or at least we try to minimize the possibility of human error.

8
00:21.900 --> 00:25.950
Now even before we were using all of these cool automation tools such as Ans

9
00:25.950 --> 00:28.000
ible or Terraform or whatever it may be,

10
00:28.000 --> 00:33.090
there were actually options to automatically schedule tasks directly on your
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

10
00:28.000 --> 00:33.090
there were actually options to automatically schedule tasks directly on your

11
00:33.090 --> 00:34.000
Linux system.

12
00:34.000 --> 00:38.000
So say for example, you wanted to perform a really, really important task,

13
00:38.000 --> 00:41.000
but let's maybe say it was at an inconvenient time.

14
00:41.000 --> 00:45.310
So let's maybe say you wanted to create some type of tar archive, a backup of

15
00:45.310 --> 00:46.000
your files,

16
00:46.000 --> 00:49.000
but basically you didn't want to do it during the week.

17
00:49.000 --> 00:53.380
Let's maybe say you wanted to perform this task at 8pm in the evening, you know

18
00:53.380 --> 00:53.500
,

19
00:53.500 --> 00:56.500
sometime well after everyone had left the office.

20
00:56.500 --> 01:01.490
Well, it would be kind of annoying to have to drive back in at 8pm, log into
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

20
00:56.500 --> 01:01.490
Well, it would be kind of annoying to have to drive back in at 8pm, log into

21
01:01.490 --> 01:03.500
the system and then perform that backup.

22
01:03.500 --> 01:05.500
Not exactly a good idea.

23
01:05.500 --> 01:09.200
Similarly, let's maybe say you wanted to perform some type of task during

24
01:09.200 --> 01:10.500
office hours,

25
01:10.500 --> 01:14.500
but you really don't want to run the risk of forgetting to do this task.

26
01:14.500 --> 01:17.000
It's so important that it cannot be missed.

27
01:17.000 --> 01:21.200
Well, once again, the solution to that type of problem would be to schedule a

28
01:21.200 --> 01:22.000
task.

29
01:22.000 --> 01:26.000
So that it executes automatically without you having to deal with it manually.

30
01:26.000 --> 01:30.000
Basically, it takes you out of the equation, you don't have to be at the system
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

31
01:30.000 --> 01:31.000
at the time of the process.

32
01:31.000 --> 01:35.060
And it also doesn't require that you remember about the process just at the

33
01:35.060 --> 01:36.500
time it's supposed to happen.

34
01:36.500 --> 01:40.160
So there are different ways to do such a thing, we can do something like a cron

35
01:40.160 --> 01:40.500
job.

36
01:40.500 --> 01:44.140
This would be a very good solution if you wanted to continually perform some

37
01:44.140 --> 01:45.000
type of task.

38
01:45.000 --> 01:50.000
However, what if you just wanted to perform some task on a one-off basis?

39
01:50.000 --> 01:53.880
Maybe you want to run a script one time at one particular hour on one

40
01:53.880 --> 01:56.000
particular date and that is it.

41
01:56.000 --> 02:00.000
In this case, the solution that we could use would be the "at" commands.
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

42
02:00.000 --> 02:04.400
Pretty much, this allows us to schedule a particular task or run a particular

43
02:04.400 --> 02:07.000
command at a very specific time.

44
02:07.000 --> 02:11.000
Say for example, let's do an LS, we can see what I have right here.

45
02:11.000 --> 02:14.730
What I'm going to do is I'm going to schedule the creation of a text file and

46
02:14.730 --> 02:17.000
let's maybe say one minute time.

47
02:17.000 --> 02:20.370
If I just say date, we can see the time is five minutes past two in the

48
02:20.370 --> 02:22.000
afternoon.

49
02:22.000 --> 02:25.000
And also it is at now plus one minute.

50
02:25.000 --> 02:31.000
All I'm going to do is echo in, "test file" into a file called "test.txt".
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

50
02:25.000 --> 02:31.000
All I'm going to do is echo in, "test file" into a file called "test.txt".

51
02:31.000 --> 02:35.420
And then once I'm done, I can press Ctrl D. Now if I happen to do an LS, notice

52
02:35.420 --> 02:37.000
the file is not yet created.

53
02:37.000 --> 02:40.000
But if I just wait that minute, then it will be created.

54
02:40.000 --> 02:44.000
So let's just do a date to see the time right now, give it a few more seconds.

55
02:44.000 --> 02:48.260
Let's do a date again, now a minute has elapsed. If I do an LS, check it out

56
02:48.260 --> 02:49.000
right here.

57
02:49.000 --> 02:53.410
The file hasn't been created. It was created exactly one minute after we had

58
02:53.410 --> 02:56.000
scheduled it as per instructions.

59
02:56.000 --> 03:00.210
So if I cat the file right there, now this is obviously a very, very trivial
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

59
02:56.000 --> 03:00.210
So if I cat the file right there, now this is obviously a very, very trivial

60
03:00.210 --> 03:01.000
example.

61
03:01.000 --> 03:04.070
Like I say, maybe you want to perform some type of backup, some type of update,

62
03:04.070 --> 03:07.000
maybe some type of check of a configuration file.

63
03:07.000 --> 03:10.240
Having the ability to do this via the "at" utility is going to allow us to

64
03:10.240 --> 03:13.000
schedule this as a one time job.

65
03:13.000 --> 03:16.770
So whilst I have the ability to perform this type of automation on this

66
03:16.770 --> 03:19.000
particular system, this is only one machine.

67
03:19.000 --> 03:24.000
What if I want to perform this task across maybe 500 machines I'm managing?

68
03:24.000 --> 03:28.000
Well I don't want to log in one by one by one by one and do that.

69
03:28.000 --> 03:32.160
That's going to take a lot of time. Instead, what if we can use Ansible to
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

69
03:28.000 --> 03:32.160
That's going to take a lot of time. Instead, what if we can use Ansible to

70
03:32.160 --> 03:35.000
effectively automate the automation?

71
03:35.000 --> 03:39.340
So that means we can push out that "at" command with the actual time that you

72
03:39.340 --> 03:40.000
want to run.

73
03:40.000 --> 03:45.000
And we can push it to all of our devices concurrently using automation.

74
03:45.000 --> 03:49.440
So if I go to my browser, if I just search for the Ansible at module, we will

75
03:49.440 --> 03:51.000
see this particular link here.

76
03:51.000 --> 03:56.000
Let's click it. Now again, notice this is part of the Ansible POSIX collection.

77
03:56.000 --> 03:59.510
So it's not going to be part of your built-in. Therefore, we're going to have

78
03:59.510 --> 04:03.000
to ensure that we do have our Ansible POSIX collection installed.
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

78
03:59.510 --> 04:03.000
to ensure that we do have our Ansible POSIX collection installed.

79
04:03.000 --> 04:06.670
We can do this via this particular command, although if you have been following

80
04:06.670 --> 04:08.000
along from previous skills,

81
04:08.000 --> 04:11.790
this particular collection should already exist on the device, but nevertheless

82
04:11.790 --> 04:13.000
, let's just type it in.

83
04:13.000 --> 04:16.690
As we can see here, I already have it. So if we check this in NOPS, as we can

84
04:16.690 --> 04:20.000
see, we can use this module to schedule a command or run a script.

85
04:20.000 --> 04:24.000
And have that run once in the future, like I say once is the key here.

86
04:24.000 --> 04:28.000
If we scroll on down, we can see some of the available options.

87
04:28.000 --> 04:31.000
We have the command parameter. This is going to take a string.
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

87
04:28.000 --> 04:31.000
We have the command parameter. This is going to take a string.

88
04:31.000 --> 04:35.130
And pretty much, this is just going to be the command that you want to run in

89
04:35.130 --> 04:36.000
the future.

90
04:36.000 --> 04:39.930
In my case here, when I happen to create that file, I run the echo command and

91
04:39.930 --> 04:41.000
pipe it into a text file.

92
04:41.000 --> 04:45.070
If I wanted that particular command to be scheduled via at using Ansible, I

93
04:45.070 --> 04:49.000
would pass that command directly into the command parameter.

94
04:49.000 --> 04:53.000
Now this part here is also important. This is the count. Notice it takes an

95
04:53.000 --> 04:54.000
integer value.

96
04:54.000 --> 04:58.310
This is the amount of units in the future that you want to have elapsed before

97
04:58.310 --> 04:59.000
the command runs.

98
04:59.000 --> 05:03.020
Now the actual unit here depends on what you specify. Are you going to do in
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

98
04:59.000 --> 05:03.020
Now the actual unit here depends on what you specify. Are you going to do in

99
05:03.020 --> 05:05.000
minutes, hours, whatever it may be?

100
05:05.000 --> 05:08.810
That can actually be controlled via another parameter. So again, if I scroll on

101
05:08.810 --> 05:13.000
down, here we have the option to specify exactly what units we want.

102
05:13.000 --> 05:16.000
So do we want to schedule something a few minutes in the future?

103
05:16.000 --> 05:20.260
Or maybe hours, perhaps some days? Or maybe even weeks in the future, we have

104
05:20.260 --> 05:24.000
this ability to specify this directly via the unit parameter.

105
05:24.000 --> 05:28.050
Now one other parameter that I just want to show you is if we just scroll on up

106
05:28.050 --> 05:29.000
a little bit.

107
05:29.000 --> 05:33.160
Now notice we have this script file option. This is the option we could use if
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

107
05:29.000 --> 05:33.160
Now notice we have this script file option. This is the option we could use if

108
05:33.160 --> 05:34.000
we actually want to run a parameter.

109
05:34.000 --> 05:37.370
We actually want to run a particular script in the future, not just a regular

110
05:37.370 --> 05:38.000
command.

111
05:38.000 --> 05:41.890
So why don't we go and give this a shot then? So the first thing I'm going to

112
05:41.890 --> 05:45.000
do is I'm going to create a very simple bash script.

113
05:45.000 --> 05:49.480
It's going to perform a very simple task. Now like I say, this is not going to

114
05:49.480 --> 05:51.000
be the most real world example.

115
05:51.000 --> 05:54.460
It's just to highlight the utility here. And you can use your imagination to

116
05:54.460 --> 05:57.660
think about all the weird and wonderful things that you could potentially do

117
05:57.660 --> 05:59.000
with a different style script.

118
05:59.000 --> 06:03.270
So let's go and create one right here. I'll just say them and I'll just say my
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

118
05:59.000 --> 06:03.270
So let's go and create one right here. I'll just say them and I'll just say my

119
06:03.270 --> 06:06.000
bash.sh and I'm going to insert mode.

120
06:06.000 --> 06:10.360
And all I will do at the top here is I'm going to add in my shebang and then

121
06:10.360 --> 06:12.000
forward slash bin forward slash bash.

122
06:12.000 --> 06:16.490
If you recall from the RHCSA examination, this is how we start off a bash

123
06:16.490 --> 06:17.000
script.

124
06:17.000 --> 06:21.060
The bash script is going to be super, super simple. All we're going to do is to

125
06:21.060 --> 06:22.000
echo in the words.

126
06:22.000 --> 06:28.580
This is just a little test and I'm going to redirect that into a file called my

127
06:28.580 --> 06:30.000
example dot txt.
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

128
06:30.000 --> 06:33.310
Okay, so we have this little script currently at resides in this particular

129
06:33.310 --> 06:35.000
directory home and simple directory.

130
06:35.000 --> 06:40.270
And what I want to do is I want this script to be present on both of my managed

131
06:40.270 --> 06:41.000
devices.

132
06:41.000 --> 06:44.000
That is the blue box and the yellow box. So what am I going to do?

133
06:44.000 --> 06:48.490
Well, I'm going to use the copy module. So let me just begin here by saying

134
06:48.490 --> 06:50.000
them play one dot ymail.

135
06:50.000 --> 06:53.630
I'll go into insert mode, have my three hyphens at the top and give the play a

136
06:53.630 --> 06:54.000
name.

137
06:54.000 --> 06:58.000
I'll just say play one copy script to targets.

138
06:58.000 --> 07:01.700
Who do I want to target? I want to target the all group and I'm going to set
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

138
06:58.000 --> 07:01.700
Who do I want to target? I want to target the all group and I'm going to set

139
07:01.700 --> 07:04.000
gather facts to the value of false to speed things up a little bit.

140
07:04.000 --> 07:08.440
Now what I'm going to do here is to find my tasks. So the task here is going to

141
07:08.440 --> 07:12.000
be called copy script to my servers.

142
07:12.000 --> 07:16.200
Now what am I going to do right here? Well, I'm going to use the Ansible built

143
07:16.200 --> 07:17.000
in copy module.

144
07:17.000 --> 07:21.040
Recall we saw this in a previous skill and this is going to allow us to copy a

145
07:21.040 --> 07:25.000
particular file from the control mode here to the target destinations.

146
07:25.000 --> 07:28.550
Now I'm going to have to supply some particular parameters namely the source

147
07:28.550 --> 07:29.000
parameter.

148
07:29.000 --> 07:33.000
Basically where can I find the file on my control machine that I want to copy
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

148
07:29.000 --> 07:33.000
Basically where can I find the file on my control machine that I want to copy

149
07:33.000 --> 07:37.000
and all I'll do is specify the path so you can find that here and home Ansible.

150
07:37.000 --> 07:42.000
And let me just check the name of the file once again. It's called my bash.sh.

151
07:42.000 --> 07:46.900
And now I specify the destination where abouts I want to copy this on the

152
07:46.900 --> 07:48.000
target device.

153
07:48.000 --> 07:50.500
Now just because this is a little demo I'll just copy it into the temp

154
07:50.500 --> 07:51.000
directory.

155
07:51.000 --> 07:56.640
So I'll copy it into temp my bash.sh so this is where it's going to be found on

156
07:56.640 --> 07:59.000
the yellow box and the blue box.

157
07:59.000 --> 08:02.450
Now one thing to note here when I happen to copy this particular file on my
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

157
07:59.000 --> 08:02.450
Now one thing to note here when I happen to copy this particular file on my

158
08:02.450 --> 08:06.000
control node to the blue box and yellow box on my targets.

159
08:06.000 --> 08:10.790
I want to make sure that this script is going to be executable because after

160
08:10.790 --> 08:13.470
all that isn't either bash script and it's going to need those particular

161
08:13.470 --> 08:14.000
permissions.

162
08:14.000 --> 08:17.850
So I'm not just going to specify that I'm going to copy this particular file

163
08:17.850 --> 08:19.000
from here to here.

164
08:19.000 --> 08:21.000
I want to ensure that it has those permissions.

165
08:21.000 --> 08:25.370
Now if you check the documentation you will see the way we can do this is by

166
08:25.370 --> 08:27.000
using the mode parameter.

167
08:27.000 --> 08:32.000
All I'm going to do here is specify the mode is going to be 0 7 5 5.
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

167
08:27.000 --> 08:32.000
All I'm going to do here is specify the mode is going to be 0 7 5 5.

168
08:32.000 --> 08:36.000
That's just the optonation to ensure that the owner has redry executable access

169
08:36.000 --> 08:41.000
and the groups and others also have red and execute.

170
08:41.000 --> 08:44.000
So with that now done what I'm going to do here is just save this for now.

171
08:44.000 --> 08:48.000
So all I will do here is say Ansible Playbook play one dot y mail and to enter.

172
08:48.000 --> 08:52.170
And as we can see here we have now copied over her scripts to those target

173
08:52.170 --> 08:53.000
devices.

174
08:53.000 --> 08:58.000
So if I see the end of the temp directory and do an LS and I just grip SH.

175
08:58.000 --> 09:02.000
As we can see here we do have this script present now on this device.
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

175
08:58.000 --> 09:02.000
As we can see here we do have this script present now on this device.

176
09:02.000 --> 09:06.740
So I cut this there is the file and similarly if we go to the blue box CDN to

177
09:06.740 --> 09:10.000
the temp directory to an LS and more grip for SH.

178
09:10.000 --> 09:15.000
Once again we also have this particular file within this particular directory.

179
09:15.000 --> 09:19.280
Now if I do an LS dash L and I grip for SH once again notice we have executable

180
09:19.280 --> 09:21.000
permissions for all groups.

181
09:21.000 --> 09:24.530
So with that now done we actually want to use the Ansible Playbook to

182
09:24.530 --> 09:28.000
effectively call those particular scripts and execute them.

183
09:28.000 --> 09:31.560
So here is what we're going to do. We'll create a new play called play two dot
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

183
09:28.000 --> 09:31.560
So here is what we're going to do. We'll create a new play called play two dot

184
09:31.560 --> 09:33.000
y mail and let's go into insert mode.

185
09:33.000 --> 09:36.730
We'll have our free hyphens at the top and we just call this play two testing

186
09:36.730 --> 09:38.000
the ads module.

187
09:38.000 --> 09:41.340
We're going to target the all-grut once again and we're also going to set

188
09:41.340 --> 09:43.000
gather facts to false once again.

189
09:43.000 --> 09:46.000
Now we'll define our tasks. In the first task we'll be task one.

190
09:46.000 --> 09:52.070
Test the service is running. So all I'll do is use the Ansible built-in service

191
09:52.070 --> 09:53.000
module.

192
09:53.000 --> 09:56.250
And now what I'm going to do is specify the service that I want to test and it

193
09:56.250 --> 09:58.000
's going to be the ad daemon.

194
09:58.000 --> 10:02.420
And now we'll specify the states and I want to ensure that it is started and I
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

194
09:58.000 --> 10:02.420
And now we'll specify the states and I want to ensure that it is started and I

195
10:02.420 --> 10:04.000
want to ensure that it is enabled.

196
10:04.000 --> 10:08.330
So if we happen to restart the server the ad service is going to automatically

197
10:08.330 --> 10:09.000
begin.

198
10:09.000 --> 10:13.150
So when we have verified that ad is indeed running an operational on our system

199
10:13.150 --> 10:15.000
we want to use that particular program.

200
10:15.000 --> 10:19.000
So we just say task two. We just say run scripts in the future.

201
10:19.000 --> 10:24.000
So what we're going to do here is use the Ansible POSIX ads module this time.

202
10:24.000 --> 10:27.320
And what I want to do is I want to specify the script file that I'm going to

203
10:27.320 --> 10:28.000
execute.

204
10:28.000 --> 10:32.340
Now where is that actually located? Well it's going to be located in the temp
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

204
10:28.000 --> 10:32.340
Now where is that actually located? Well it's going to be located in the temp

205
10:32.340 --> 10:35.000
directory and it's called my bash dot SH.

206
10:35.000 --> 10:39.000
This is the path for the file on both of the target devices.

207
10:39.000 --> 10:42.000
Now what I want to do here is to specify my counts.

208
10:42.000 --> 10:45.000
So in my case here let's do with account of two.

209
10:45.000 --> 10:48.750
And now I specify the unit. Well two what is it two hours two weeks two minutes

210
10:48.750 --> 10:49.000
?

211
10:49.000 --> 10:52.180
What is it? Well because as a demo we don't want to wait forever so I'll just

212
10:52.180 --> 10:53.000
say two minutes time.

213
10:53.000 --> 10:56.850
Now before I actually run this what I want to do is verify that the script has

214
10:56.850 --> 10:58.000
not actually ran yet.

215
10:58.000 --> 11:02.000
So let me go in as the Ansible user here and I'll type in the password Ansible.
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

215
10:58.000 --> 11:02.000
So let me go in as the Ansible user here and I'll type in the password Ansible.

216
11:02.000 --> 11:05.000
If I do a CD I'm now in the Ansible home directory.

217
11:05.000 --> 11:09.000
If I do an LS we have not actually got any particular files right here.

218
11:09.000 --> 11:13.190
However once the script has ran as per the scheduling that particular file is

219
11:13.190 --> 11:15.000
short and the home directory of the Ansible user.

220
11:15.000 --> 11:20.000
So I will just say Ansible Playbook play two dot yml and to enter.

221
11:20.000 --> 11:23.550
We'll test the service as it running. The Playbook executes if I go back to my

222
11:23.550 --> 11:24.000
yellow box.

223
11:24.000 --> 11:28.000
Inside of this home directory if I do an LS the file has not yet been created

224
11:28.000 --> 11:30.000
because the script has not executed.
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

225
11:30.000 --> 11:35.280
However in about nine seconds time the script will have been executed and it

226
11:35.280 --> 11:38.000
will generate the file within this particular directory.

227
11:38.000 --> 11:42.210
So again now we have executed if I do an LS now the file actually has been

228
11:42.210 --> 11:43.000
generated.

229
11:43.000 --> 11:47.050
Check this out and if I go over to the blue box if I just substitute user

230
11:47.050 --> 11:50.000
become the Ansible user and just type in the password Ansible.

231
11:50.000 --> 11:53.660
If I see you to the home directory and on LS we can also see the file has also

232
11:53.660 --> 11:58.000
been generated within the home directory of the Ansible user on the blue box as

233
11:58.000 --> 11:58.000
well.

234
11:58.000 --> 12:02.000
And all of this was scheduled via the @utility via Ansible.
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

234
11:58.000 --> 12:02.000
And all of this was scheduled via the @utility via Ansible.
