Okay, so let's walk through this solution then.
So the very first thing that I'm going to have to do is to use Ansible Nav
igator to display
my inventory in both JSON and YAML formats.
So the command I can use is Ansible Navigator Inventory and then -i and then
provide my
inventory which is called in my case here, inventory.ini.
Then I'm going to use standard out to print it to the terminal and I'm going to
say - -list.
And when I do this, what we actually see here is the contents of our inventory WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
And when I do this, what we actually see here is the contents of our inventory
in JSON format.
Now if I want to see in YAML format, I can say -y and that will transform the
data to
be rendered as YAML.
So that is the first thing we had to do.
The next thing we're going to have to do is to open the documentation for the
built-in
debug module directly on the terminal.
So what I will do is I will say Ansible.doc -L to get a list and we can see the
debug module
is this one right here.
So let's just grab this, copy here, press Q2Quit, clear the screen, we'll just
say Ansible.doc
and then paste in the name of this particular module and now we have access to WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
and then paste in the name of this particular module and now we have access to
the documentation
for that debug module right there.
So once again Q2Quit, what I'm going to have to do now is to create a file on
one of my
managed devices called temp validation-check.txt.
So in my case here, I will choose the yellow box, doesn't actually matter which
one you
pick and all I will do is I'll go to the temp directory or rather forward slash
temp
and I will just say touch validation-check.txt if I don't ls, now the file is
present. WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
present.
So the next thing I'm going to have to do is to create a playbook that is going
to check
for the presence of this particular file on both machines.
That means it should find it on the yellow box but not find it on the blue box.
So back to the control node, let me just create a file called validation.yml
from my
playbook, going to insert mode to have my three hyphens and I'll give this a
name and
just call this validation play.
Now I'm going to check it on both of my devices so I will set my horse to be
all.
I'm going to set gather facts to false not that it's necessary but it does
speed things
up and now I define my tasks. WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
up and now I define my tasks.
So I will give the task a name and I'll just say check the validation file
exists.
Now the module I'm going to use is going to be the Ansible built in stat module
and the
path I'm going to provide here is forward slash temp forward slash validation-
check.txt.
Now to capture the output I will use the register module and I'll just call
this stat output.
Now I'll have a new task and I'll just call this print the result.
So I'll use the debug module with the var parameter and all I want to do is to
print
stat outputs.
Now if I press escape call on wq to write and quit we now have this playbook. WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
Now if I press escape call on wq to write and quit we now have this playbook.
Now what we actually want to do is we want to run this playbook within an Ans
ible Navigator
execution environment.
So what I will do here is say Ansible Navigator run validation.yml and to get
the output on
my terminal as normal I will say -m s to the out that's just a preference you
don't
have to do this.
So if I enter give it a moment the playbook executes and as we can see here we
have a result.
So if I scroll on up for the yellow box we can see the stat output has a whole WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
So if I scroll on up for the yellow box we can see the stat output has a whole
bunch
of information that's because the file does exist right here and we can confirm
this via
the fact that the exist key is set to the value of true whereas if I scroll on
up to the blue
box just a little bit higher we can see here the blue box.
The stat module is telling us that this file does not exist on this particular
device.
So that is us for our validation challenge I hope this has been informative for
you and
I'd like to thank you for viewing.