Okay friends, so let's talk about the solution now.
So think about it like this.
We're going to have to create a playbook
that's going to append the current date and time
configuration for all devices into a text file
within the temp directory called date_info.txt.
And crucially, this is going to be updated every three minutes.
So when you hear about a task that is going to have
to be repeated on a regular basis,
you should be thinking towards utilizing coron.
So it's no surprise then that this is a particular module
that we want to be using.
So coron is going to allow us to actually schedule WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
So coron is going to allow us to actually schedule
how often a particular task should happen.
But the question is, how do we actually perform the tasks
that we've been asked to do?
Well, think about it like this.
How do we actually get the current time and date information?
Well, if we go to our devices here,
let's go into device number one, for example.
If I just type the command dates,
we actually get the current time and date information
right there, okay?
And if we wanted to perhaps append it into a text file,
we could have our double arrows
and then just specify the name of the files.
So let's just say text.txt. WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
So let's just say text.txt.
And if I run it again and again and again,
if I eventually cut this particular file,
we can see here the actual output here.
We can see it's running on 32 seconds
and 33 and 34th, so on and so forth.
So basically we want to run this particular command.
Only difference is we want to have a different output path
and we want to run it every three minutes.
So let's go and learn how we can actually do such a thing.
So we'll go back to our terminal right here.
And if I say Ansible.dash-list.
And if I just do forward slash and search for cron,
we can see here we have the Ansible built in cron module. WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
we can see here we have the Ansible built in cron module.
So let's go and check the documentation
for this particular module.
Okay, perfect.
So as we can see here,
if we look at the documentation,
we have some available options to us.
We can see the job option,
which is the actual command we want to execute.
And if we scroll on down,
we're going to get to see some simple examples.
So again here in the example here,
we use the Ansible built in cron module.
We specify a name for the actual task.
Let me specify, say for example,
the minute or the hour,
whatever you happen to be using.
And then we have the job keyword.
So let's go and use this information WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
So let's go and use this information
to build out our cron jobs.
Let's just say them cronconfig.yml.
Going to inset mode,
have our three hyphens at the top.
Give a playbook a name.
We'll just say schedule cron stuff.
The name itself doesn't actually matter.
We'll set the host to be all
and gather facts will be set to false.
So now what we want to do is we want to define our tasks.
And this task can have a name of just simply
writing into text file every three minutes.
Okay, so what I will do here is I'll specify the minute option.
Now if I use the asterisk,
this will be for every minute. WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
And if I say forward slash three,
this will be every third minute.
And now what I can do here is specify the job
that I want to run.
Well, what exactly is the command
that I want to run?
I want to say dates
and I want to append it, not overwrites.
So remember we have our two arrows
and then I specify the path that I want to use.
So if we consult the actual question again,
the path is going to be in the temp directory
and the file should be date on the score info.txt.
So let's populate that.
So forward slash tmp forward slash dates on the score info.txt.
And let's press escape colon wq to rank WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
And let's press escape colon wq to rank
quite in fact before I even do that.
Let's go back and totally missing something here.
You probably have recognized any
to put the actual module and so
wake up John Boyle, let's try this again.
We'll say Ansible built in cron.
This looks a little bit better.
And I'll just indent this two spaces.
So one two and again, one two for you.
Escape colon wq to rank with this time.
So let's try this.
Okay Ansible Playbook cron config.yml
hit enter give it a moment and we have a problem. WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
hit enter give it a moment and we have a problem.
Oh, that appears our syntax is causing a little bit
of history. Let's go back in.
And all we'll do here is add in my quotation marks
so it's a string that looks a little bit better.
So let's just save this and add a warp and try again.
Oh, we happen to have an error.
We have a require parameter that is missing.
We need to have the name parameter.
And again, if I happen to consult the documentation
a little bit more thoroughly, like so, if I go down,
we actually see in the output the name parameter
actually has an equal sign, which if you recall
when we talked about Ansible Docs,
this means this is a require parameter.
So just be aware of that. WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
So just be aware of that.
So I'm going to have to specify a name for the job itself.
So let's go back in and I'll give it a name
and let's just call this date job.
Okay, so let's just save this and let's try again.
So this looks a lot better.
So if I log in to the device, all I've done is wait three
minutes so that time has elapsed.
If I see the end of the 10th directory and do an LS,
we now see our date info.txt file.
So let's cat this.
We can see we have it to have an entry right here.
And if I gain, wait for three more minutes,
this should be updated.
So if I run the date command once again,
we're almost at nine minutes past the hour. WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
we're almost at nine minutes past the hour.
Let's run it again.
Now, but at nine minutes, if I now cat the file,
we should see a new entry.
So let's go in here.
And as we can see here, three minutes later,
we have actually updated the information
within this text file.
So that is us for a little mock exam preparation.
Good luck, give it some practice.
I know you're going to do great,
but for now, I hope this has been informative for you.
I'd like to thank you for viewing.