So friends, let's walk through the validation solution.
So the very first time we're going to have to do is to create a playbook called
validation.yml.
So let's start with that. So let's create this hit enter.
Let's go into insert mode, have our three hyphens at the top.
And the first place should only target one of your managed nodes.
So in my case here, I will just target my blue box device.
I'll set gather facts to be false.
Now what I should attempt to do here is to create a directory called forward
slash TMP
forward slash validation and handle any errors.
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
So let me define my tasks right here and the very first time I'm going to have
to do it to
define my block keywords. So inside of here, sort of say, create the validation
directory
and I will use the Ansible built in file module, which we've seen before,
or specify the path that I want to target is going to be forward slash TMP
forward slash validation.
Okay, then the state is going to be a directory.
And now at the same level of indentation, I want to have my rescue message,
sort of say,
print custom error message. So now I want to do is to use my Ansible built in
debug module.
And the message is simply going to be error creating the validation there. WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
And the message is simply going to be error creating the validation there.
Now, regardless of whether or not we have a diverse success, we always want to
run my
particular commands. So the name here will just be simply a long list of
contents of the temp
directory. And I'll use the Ansible built in shell module. And I'll just say,
LS dash L against TMP. Now, in order to actually see the output here, I want to
register this.
So I'll register this as a variable, which is called as list output.
And now I'll have another task, which is going to be print the outputs. So
again,
I'll use the Ansible built in debug module. And this time here, I'll print at
the variable list WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
the variable list
outputs. Okay, so what I want to do now is to create a second play. So again, I
got all the way
to the margin once again, I'll just do dash name to give it a name. I'll just
call this play too.
Now this time, I should be targeting everyone in my inventory, i.e. the all
group. And what I'm
going to do here is to find my tasks. So the first task is going to have a name
. I'm just going to
say copy fails to target. So this time, I will use the Ansible built in copy
module. So specify
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
the SRC, which is going to be home Ansible. And the first file will be
validation 1.txt.
I'm still going to have to create this on my own machine. And now I specify the
destination.
I will just put in the home directory of the nugget user, but again, choose any
directory
used to wish on your machine. And again, it's going to be called validation 1.
txt. Now, if you
so wish, what you could do is build this module with a particular loop, but in
the interest of
keeping things nice and simple, let's just do another task. And let's maybe
just change this,
copy fail 1 to target. And let's have a second task, just say copy fail 2.
Again, let's specify
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
the source. This one will be validation 2.txt and the destination forward slash
home forward slash
nugget user, and then validation 2.txt. So once these fails happen to be copied
over,
what we now want to do is to create an archive of these fails using the bzip2
compression.
So let's create a new task, just to create a compressed archive. This time, a
user community
general archive module, so we'll specify the path. So in this case, here, it's
going to be the
forward slash home nugget user directory. And then what I want to do is I want
to use fail
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
globing. So I'll say validation, and then a question mark dot txt. So that will
include validation 1.txt
as well as validation 2.txt. And now I want to specify the destination where
this archive is
going to be kept. And you can specify any destination user wish. Let's put this
in the temp directory.
And let's just call this validation archive dot tar dot bz2. Now the format is
going to be
bz2 compression. And that should be pretty much it. What we have to do though
is to create these
particular files validation 1 and validation 2 within the answerable home WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
particular files validation 1 and validation 2 within the answerable home
directory here on
the control node. So like I say within this particular directory, I'll create
fail call validation 1.txt.
Going to insert more than say this is validation 1 and also create validation 2
.txt. And just
say this is validation number two. So let's just save here. And let's try to
run the validation
playbook. So let's hit enter play one executes. And now the second play
executes. So let's check
the actual results here. And let's just scroll up a little bit to ensure that
we actually got the
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
output over LS command, which we did right here. See this right here. Now the
output here is not
really the pretty is what I should actually have done is if I go back in, as I
should actually
have printed just the A to the out lines attributes, that would make it a
little bit prettier. But
nevertheless, we do see the presence of this validation directory. And we can
see it's a directory
because we have this de-present in the output. And if we go actually to the
blue box right here
and we do see the into validation, we can indeed see here, we do actually have
a directory. Now
effectively in both devices, we send the temp directory, we should also have
this archive file WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
this archive file
validation, haven't archive dot tar dot bz2. So let's go to the blue box, go
back a directory.
Let's do an LS. There we can see we have our validation archive dot tar dot bz2
. And on the
yellow box, if we go into the 10th directory and doing LS, we can also see we
have our validation
archive dot tar dot bz2. And if it happens to tar dot x, lowercase j on the
file of validation
archive and enter, if I do an LS, we actually see the contents here are the
correct text fails
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
validation one and validation two. And again, if I happen to open these via the
cat command,
there is the content and there is a content and the same thing is true over on
the blue box. Now
one thing I want to show you here is just to ensure that our blog is actually
working correctly.
So notice on the blue box, we actually have this validation directory we've
just created. What I
will do here is I'll just delete it. Okay. So it no longer exists. What I will
do though,
is I'm going to actually create a file just called validation. So now we have
this one here,
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
but as we can see, it's not actually directory. It's just a regular file. So
what this means is
that when the system goes to try to recreate this directory, it's going to
encounter an error
because we have a conflict between a file name and the directory name we're
trying to create.
This should provoke an error. And we want to see if we handle that error. So
let's go for it then.
So let's clear the screen. We'll say Ansible playbook validation dot yml. And
to enter. Okay.
So notice we don't actually have to copy any files or create a new compressed
archive that
already exists on the target. However, if we scroll on up, this is where the
interesting bit is. WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
interesting bit is.
Look at this right here. We have an error trying to create our validation
directory.
However, we can see here we have successfully handled that error. And we are
printing out the
custom error message. Now what we're going to do is we're going to list the
contents of the TMP
directory, which we can see right here. And as we can see here, the validation
file here is not
actually a directory. So crucially, like you can see the playbook continued to
execute despite
that initial failure. So that is us for a validation challenge. I hope it's
been informative for you.
I'd like to thank you for viewing. WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
I'd like to thank you for viewing.