Okay, so let's walk through the validation challenge.
The very first thing we're going to have to do is to write a playbook that is
going to
install the Redis package on both managed devices and ensure the service has
started
and will automatically start every time the system is rebooted.
So what I will do here is create a playbook, let's just call this validation1.Y
ML.
We're going to insert modes and let's just call this validation play1.
I'm going to target the all group and I'll set my gather facts to be false.
Now what I'll do is define my tasks and this task will be called installRedis. WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
Now what I'll do is define my tasks and this task will be called installRedis.
So in order to install Redis I will use the dnf module,
it's also answerable built-in dnf.
The name is going to be Redis and I want the state to be present.
Now I want to ensure that the service is started and enabled.
So I'll use the built-in service module right here and the name of the service
will be Redis.
The state should be started and enabled should be set to the value true.
So if I just save this here and I run the playbook and to enter,
as we can see here we have now started and enabled Redis. WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
as we can see here we have now started and enabled Redis.
Now the next task is to write another playbook that is going to manage the
default boot target
configuration and this playbook should be id important.
So let's just call this one validation2.YML.
We'll just call this manage boot target, the host I'm going to target, again
will be all
and gather facts as set to false.
Now what I will do here is define a variable to specify what my default target
should actually be.
And in this case here I will just set it to be graphical.target.
Now I'll define my tasks and I'm going to use the Ansible built-in command WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
Now I'll define my tasks and I'm going to use the Ansible built-in command
module
and the command I'm going to run is systemctl gets hyping default.
I'll use the changed when parameter and set the value to false.
I'm going to register the output as default outputs and I'll use the Ansible
built-in
debug module and all I'm going to print out is the default output variable.
Now I'll create a playbook to actually change the default value if required.
Once again I'm going to use the built-in command module.
This time though the command is going to be systemctl set hyping default and I WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
This time though the command is going to be systemctl set hyping default and I
'm going to use my
double curly braces to pull in my default underscore target variable I have to
find.
I only want it to run on a conditional basis to ensure that it is id important
and I'll specify when the default target variable is not in the default output.
astdouts.
And in fact let me just change the print statement to only print out the stdout
attribute.
So I'll notify my handler called reboot system.
So now I'll create my handler go into spaces.
The handler name will be reboot system and I'll use the Ansible built-in reboot WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
The handler name will be reboot system and I'll use the Ansible built-in reboot
module
and I can specify the reboot timeout.
So again I will set this at 60 seconds if you need longer then by all means set
it to longer.
So I'll just save this if I rerun the playbook and to enter as we can see here
the playbook runs
and because we have built in the idempotency we did not seek to make a change
because the
current target actually matches the default target that we desired and
therefore of course we
happen to specify we wanted a different value then we would invoke the set WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
happen to specify we wanted a different value then we would invoke the set
default command
as well as calling your handler.
So the next thing I'm going to do is to write a bash script called echo date SH
.
So let me just put this in the temp directory just for simplicity and I'll
create echo date SH.
So I'll have my shebang bin bash at the top and all I'm going to do is to echo
out the content of
my date and I will append it into a text file.
So I'll just call this once again in the temp directory I'll just call this
validation.txt
And with that now created what I'm going to have to do is to write an Ansible WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
And with that now created what I'm going to have to do is to write an Ansible
playbook that is going
to run this script on a daily basis.
So we'll create a playbook called validation three we'll target the all group.
I will define my tasks.
The first thing I want to do is to ensure that the script is available on both
of my devices.
So I'll use the Ansible built in copy module and the source is going to be temp
echo hyphen date
dot SH and I'm going to copy that over to the same location on the managed
devices.
Let's make sure the script is executable.
So I'll have the auto permissions 0755 and now I want to run the script on a WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
So I'll have the auto permissions 0755 and now I want to run the script on a
daily basis.
So I want to use the Ansible built in cron module.
The name is going to be daily execution of script and I'll specify that the
special time is going to be
the value of daily and now I will specify what the job actually is.
So what I will do is I'll give the path to the script to be executed.
So it's going to be in the temp directory.
It's going to be echo date dot SH and I'll specify that the user is going to be
the
Ansible user and the last thing I will do is I will set gather facts to be the WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
Ansible user and the last thing I will do is I will set gather facts to be the
value false.
So let's give this a go.
If I say Ansible playbook validation three dot yml and to enter we copy over
the script
and now we schedule the script's execution to be run on a daily basis.
So let's go to our devices.
So let me become the Ansible user.
Our login is Ansible.
If I cd to the temp directory and I do an LS and I grip for echo,
I should see my script right here and if as the Ansible user I say crontab dash
l,
we can actually see here we have a crontab schedule specified that we want to WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
we can actually see here we have a crontab schedule specified that we want to
have the daily
execution of our script.
So that is us for our validation challenge.
I hope it's been informative for you and I'd like to thank you for viewing.