WEBVTT

1
00:00.000 --> 00:02.580
Okay friends, so let's talk about the solution now.

2
00:02.580 --> 00:04.080
So think about it like this.

3
00:04.080 --> 00:05.480
We're going to have to create a playbook

4
00:05.480 --> 00:08.160
that's going to append the current date and time

5
00:08.160 --> 00:10.760
configuration for all devices into a text file

6
00:10.760 --> 00:14.240
within the temp directory called date_info.txt.

7
00:14.240 --> 00:18.520
And crucially, this is going to be updated every three minutes.

8
00:18.520 --> 00:20.600
So when you hear about a task that is going to have

9
00:20.600 --> 00:22.800
to be repeated on a regular basis,

10
00:22.800 --> 00:25.480
you should be thinking towards utilizing coron.

11
00:25.480 --> 00:28.200
So it's no surprise then that this is a particular module

12
00:28.200 --> 00:29.600
that we want to be using.

13
00:29.600 --> 00:31.640
So coron is going to allow us to actually schedule
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

13
00:29.600 --> 00:31.640
So coron is going to allow us to actually schedule

14
00:31.640 --> 00:34.320
how often a particular task should happen.

15
00:34.320 --> 00:37.000
But the question is, how do we actually perform the tasks

16
00:37.000 --> 00:38.320
that we've been asked to do?

17
00:38.320 --> 00:39.640
Well, think about it like this.

18
00:39.640 --> 00:42.800
How do we actually get the current time and date information?

19
00:42.800 --> 00:44.600
Well, if we go to our devices here,

20
00:44.600 --> 00:47.040
let's go into device number one, for example.

21
00:47.040 --> 00:49.000
If I just type the command dates,

22
00:49.000 --> 00:51.440
we actually get the current time and date information

23
00:51.440 --> 00:52.600
right there, okay?

24
00:52.600 --> 00:55.440
And if we wanted to perhaps append it into a text file,

25
00:55.440 --> 00:56.760
we could have our double arrows

26
00:56.760 --> 00:58.360
and then just specify the name of the files.

27
00:58.360 --> 01:00.520
So let's just say text.txt.
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

27
00:58.360 --> 01:00.520
So let's just say text.txt.

28
01:00.520 --> 01:03.240
And if I run it again and again and again,

29
01:03.240 --> 01:05.760
if I eventually cut this particular file,

30
01:05.760 --> 01:07.280
we can see here the actual output here.

31
01:07.280 --> 01:09.040
We can see it's running on 32 seconds

32
01:09.040 --> 01:11.920
and 33 and 34th, so on and so forth.

33
01:11.920 --> 01:14.200
So basically we want to run this particular command.

34
01:14.200 --> 01:16.960
Only difference is we want to have a different output path

35
01:16.960 --> 01:19.840
and we want to run it every three minutes.

36
01:19.840 --> 01:22.360
So let's go and learn how we can actually do such a thing.

37
01:22.360 --> 01:24.320
So we'll go back to our terminal right here.

38
01:24.320 --> 01:26.880
And if I say Ansible.dash-list.

39
01:26.880 --> 01:29.520
And if I just do forward slash and search for cron,

40
01:29.520 --> 01:32.440
we can see here we have the Ansible built in cron module.
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

40
01:29.520 --> 01:32.440
we can see here we have the Ansible built in cron module.

41
01:32.440 --> 01:34.000
So let's go and check the documentation

42
01:34.000 --> 01:35.640
for this particular module.

43
01:35.640 --> 01:36.480
Okay, perfect.

44
01:36.480 --> 01:37.320
So as we can see here,

45
01:37.320 --> 01:38.280
if we look at the documentation,

46
01:38.280 --> 01:40.200
we have some available options to us.

47
01:40.200 --> 01:41.160
We can see the job option,

48
01:41.160 --> 01:43.320
which is the actual command we want to execute.

49
01:43.320 --> 01:45.200
And if we scroll on down,

50
01:45.200 --> 01:47.520
we're going to get to see some simple examples.

51
01:47.520 --> 01:49.040
So again here in the example here,

52
01:49.040 --> 01:51.080
we use the Ansible built in cron module.

53
01:51.080 --> 01:53.280
We specify a name for the actual task.

54
01:53.280 --> 01:54.760
Let me specify, say for example,

55
01:54.760 --> 01:55.720
the minute or the hour,

56
01:55.720 --> 01:56.880
whatever you happen to be using.

57
01:56.880 --> 01:58.800
And then we have the job keyword.

58
01:58.800 --> 02:00.600
So let's go and use this information
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

58
01:58.800 --> 02:00.600
So let's go and use this information

59
02:00.600 --> 02:01.920
to build out our cron jobs.

60
02:01.920 --> 02:05.680
Let's just say them cronconfig.yml.

61
02:05.680 --> 02:06.520
Going to inset mode,

62
02:06.520 --> 02:08.040
have our three hyphens at the top.

63
02:08.040 --> 02:09.640
Give a playbook a name.

64
02:09.640 --> 02:10.840
We'll just say schedule cron stuff.

65
02:10.840 --> 02:12.760
The name itself doesn't actually matter.

66
02:12.760 --> 02:14.080
We'll set the host to be all

67
02:14.080 --> 02:17.080
and gather facts will be set to false.

68
02:17.080 --> 02:19.760
So now what we want to do is we want to define our tasks.

69
02:19.760 --> 02:21.880
And this task can have a name of just simply

70
02:21.880 --> 02:24.640
writing into text file every three minutes.

71
02:24.640 --> 02:27.560
Okay, so what I will do here is I'll specify the minute option.

72
02:27.560 --> 02:28.840
Now if I use the asterisk,

73
02:28.840 --> 02:30.000
this will be for every minute.
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

74
02:30.000 --> 02:31.760
And if I say forward slash three,

75
02:31.760 --> 02:34.040
this will be every third minute.

76
02:34.040 --> 02:36.040
And now what I can do here is specify the job

77
02:36.040 --> 02:37.120
that I want to run.

78
02:37.120 --> 02:38.320
Well, what exactly is the command

79
02:38.320 --> 02:39.160
that I want to run?

80
02:39.160 --> 02:40.000
I want to say dates

81
02:40.000 --> 02:42.080
and I want to append it, not overwrites.

82
02:42.080 --> 02:43.560
So remember we have our two arrows

83
02:43.560 --> 02:45.560
and then I specify the path that I want to use.

84
02:45.560 --> 02:47.800
So if we consult the actual question again,

85
02:47.800 --> 02:49.600
the path is going to be in the temp directory

86
02:49.600 --> 02:52.240
and the file should be date on the score info.txt.

87
02:52.240 --> 02:53.560
So let's populate that.

88
02:53.560 --> 02:58.560
So forward slash tmp forward slash dates on the score info.txt.

89
02:58.560 --> 03:01.280
And let's press escape colon wq to rank
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

89
02:58.560 --> 03:01.280
And let's press escape colon wq to rank

90
03:01.280 --> 03:03.680
quite in fact before I even do that.

91
03:03.680 --> 03:05.880
Let's go back and totally missing something here.

92
03:05.880 --> 03:07.200
You probably have recognized any

93
03:07.200 --> 03:08.840
to put the actual module and so

94
03:08.840 --> 03:11.000
wake up John Boyle, let's try this again.

95
03:11.000 --> 03:13.240
We'll say Ansible built in cron.

96
03:13.240 --> 03:15.000
This looks a little bit better.

97
03:15.000 --> 03:16.760
And I'll just indent this two spaces.

98
03:16.760 --> 03:20.400
So one two and again, one two for you.

99
03:20.400 --> 03:22.560
Escape colon wq to rank with this time.

100
03:22.560 --> 03:23.920
So let's try this.

101
03:23.920 --> 03:27.160
Okay Ansible Playbook cron config.yml

102
03:27.160 --> 03:30.320
hit enter give it a moment and we have a problem.
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

102
03:27.160 --> 03:30.320
hit enter give it a moment and we have a problem.

103
03:30.320 --> 03:32.200
Oh, that appears our syntax is causing a little bit

104
03:32.200 --> 03:33.600
of history. Let's go back in.

105
03:33.600 --> 03:35.800
And all we'll do here is add in my quotation marks

106
03:35.800 --> 03:37.880
so it's a string that looks a little bit better.

107
03:37.880 --> 03:41.120
So let's just save this and add a warp and try again.

108
03:41.120 --> 03:42.440
Oh, we happen to have an error.

109
03:42.440 --> 03:44.560
We have a require parameter that is missing.

110
03:44.560 --> 03:46.240
We need to have the name parameter.

111
03:46.240 --> 03:48.280
And again, if I happen to consult the documentation

112
03:48.280 --> 03:51.640
a little bit more thoroughly, like so, if I go down,

113
03:51.640 --> 03:53.920
we actually see in the output the name parameter

114
03:53.920 --> 03:56.200
actually has an equal sign, which if you recall

115
03:56.200 --> 03:57.800
when we talked about Ansible Docs,

116
03:57.800 --> 03:59.680
this means this is a require parameter.

117
03:59.680 --> 04:00.520
So just be aware of that.
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

117
03:59.680 --> 04:00.520
So just be aware of that.

118
04:00.520 --> 04:03.320
So I'm going to have to specify a name for the job itself.

119
04:03.320 --> 04:05.480
So let's go back in and I'll give it a name

120
04:05.480 --> 04:06.880
and let's just call this date job.

121
04:06.880 --> 04:10.120
Okay, so let's just save this and let's try again.

122
04:10.120 --> 04:12.040
So this looks a lot better.

123
04:12.040 --> 04:14.960
So if I log in to the device, all I've done is wait three

124
04:14.960 --> 04:16.600
minutes so that time has elapsed.

125
04:16.600 --> 04:18.680
If I see the end of the 10th directory and do an LS,

126
04:18.680 --> 04:21.400
we now see our date info.txt file.

127
04:21.400 --> 04:22.480
So let's cat this.

128
04:22.480 --> 04:24.320
We can see we have it to have an entry right here.

129
04:24.320 --> 04:26.400
And if I gain, wait for three more minutes,

130
04:26.400 --> 04:27.840
this should be updated.

131
04:27.840 --> 04:29.680
So if I run the date command once again,

132
04:29.680 --> 04:32.040
we're almost at nine minutes past the hour.
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

132
04:29.680 --> 04:32.040
we're almost at nine minutes past the hour.

133
04:32.040 --> 04:32.960
Let's run it again.

134
04:32.960 --> 04:35.240
Now, but at nine minutes, if I now cat the file,

135
04:35.240 --> 04:36.400
we should see a new entry.

136
04:36.400 --> 04:37.240
So let's go in here.

137
04:37.240 --> 04:39.920
And as we can see here, three minutes later,

138
04:39.920 --> 04:42.040
we have actually updated the information

139
04:42.040 --> 04:43.280
within this text file.

140
04:43.280 --> 04:46.480
So that is us for a little mock exam preparation.

141
04:46.480 --> 04:47.880
Good luck, give it some practice.

142
04:47.880 --> 04:49.080
I know you're going to do great,

143
04:49.080 --> 04:51.160
but for now, I hope this has been informative for you.

144
04:51.160 --> 04:52.540
I'd like to thank you for viewing.
