So friends in the previous video we learned how we could install Ansible Nav
igator and
we learned how to modify some basic settings with that now done.
Let's get hands on and begin using it to run our playbooks.
Now the first thing to state is that with respect to our Ansible Navigator,
notice I
am in a directory whereby I actually have a configuration filter rather an
inventory
file.
This is the inventory.ini.
If we have a look at this right here, we can see no surprises.
It is in the INI format as specified via the suffix. WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
It is in the INI format as specified via the suffix.
Now if I just escape out here, check out what I can do here directly with Ans
ible Navigator.
If I just say Ansible Navigator and I use the keyword inventory and then I
specify the
inventory file is going to be my inventory INI using the i flag.
Watch what happens if I hit answer here.
Right now it's taking me into my text user interface so I can either browse
groups or
browse hosts.
If I want to browse groups, look at the number to the left, it is number zero,
so I'll just
press zero here and we can see right here we have access to all of our groups. WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
press zero here and we can see right here we have access to all of our groups.
We have the ones we have defined as well as the automatically generated ungroup
ed group
and if I go back, I press escape.
If I press the number one, we go into the actual host we have, you see this?
This is a nice easy way to browse all of the hosts and all of the groups and
all the nested
groups within a particular inventory file directly via this text user interface
.
Now that is via the text user interface.
Recall in the previous video, we could also look at things via standard.
So if I just use the dash M flag and say STD out and to enter, absolutely WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
So if I just use the dash M flag and say STD out and to enter, absolutely
nothing is going
to happen because I'm going to have to add in the option dash dash list.
I was forgetting that there if I hit enter now, check this out.
What it's done here is actually presented our inventory in JSON format.
Now you may notice we don't just have the inventory, we also are seeing the
host variable.
So we can see the host files we defined for blue box, which are the DNS servers
and the
domain info, same for yellow box, we have DNS servers domain info.
This is a nice way to easily interpret what you actually have within your WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
This is a nice way to easily interpret what you actually have within your
inventory.
Like I say, I and I is easier to read, but this type of structure format such
as JSON
or YAML is a little bit easier when the data becomes more complex and nested.
So this is a good way to actually read your output or if you so wish, convert
your outputs.
So this is the JSON format.
If I actually add a dash Y flag here, we're actually going to see the same type
of information
or inventory data this time in YAML.
So if I enter here, check this out.
Look at that. WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
Look at that.
It's actually been converted directly into YAML.
So if I so wish that I wanted to create a copy of this, what I could do is just
read
the right output to inventory dot I and I dot backup.
And if I do an LS, I now have a copy of this particular file.
And if I so wish, I could actually just rename this as my inventory file and
use it because
it has been correctly formatted.
It has all of our data.
So Ansible Navigator really makes it easy to effectively work with your
inventory and
modify as needed.
With that now said, let's actually use Ansible Navigator to connect to the WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
With that now said, let's actually use Ansible Navigator to connect to the
devices within our
inventory this time using an Ansible playbook.
Now first thing I want to do here, if I go in and I just say play one dot YAML,
let's
go into Incent mode, have my three hyphens at the top to denote a YAML file and
I'll give
this playback a name, which is called this play one.
Now the host I'm going to target is going to be the local host.
This means we're not going to connect to the managed devices in our network.
Instead, we are going to just connect to our own local machine, the Ansible
control
node.
So what I will do here is say my tasks I wanted to find. WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
So what I will do here is say my tasks I wanted to find.
I'll give it a name and all I'm going to do here is just say prints the host
name and
all I'm going to do is use the debug module and then I'll use the var parameter
and all
I'm going to print out is the Ansible host name.
Now check this out.
If I just say Ansible playbook, play one and to enter, we gather the facts and
no surprises
there.
We actually see the name of the device is called red box.
Okay.
So that is running a playbook as we ordinarily would.
What if I just say Ansible hyphen navigator this time and I want to run the WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
What if I just say Ansible hyphen navigator this time and I want to run the
playbook via
navigator so within the actual container, if I say run and then specify the
name of the
playbook, which is play one and I want to see the output in the same regular
format.
So I'll say dash in STD out.
And if I hit answer here and give it a moment, we're going to gather the facts.
Look at the Ansible host name.
This is really quite different.
Why does it not actually say red box, which is the machine?
Well, that is because what is actually happening is that we are running the Ans
ible automation
system with their container.
This is actually a container ID right here. WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
This is actually a container ID right here.
So how about we actually write a playbook to connect to our managed devices
this time
and utilize the execution via Ansible navigator.
So what we'll do here is I'll just create a playbook called play two dot yml
and I'll
try to spell that correctly this time.
There we go.
And we're going to insert mode, have our free hyphen to the top and the name we
're going
to give this one is you guessed it play number two, just to connect to devices.
Now the host this time is going to be the all grip that is going to target both
devices
the blue box and the yellow box within earth apology. WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
the blue box and the yellow box within earth apology.
And in this case here, I'm just going to set the gather facts to false.
We don't need to gather facts.
It's just going to slows down.
So let's just turn it off.
What I will also do is to find my tasks.
I'll give the first task a name and that name is going to be check the host
name of the
device.
Now recall from the previous skill we talked about being able to register a
particular command.
That is exactly what we're going to have to do.
So what I will first do is use my Ansible built in command module and the
command I'm
going to run is simply the host name commands. WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
going to run is simply the host name commands.
Then we'll use the register keyword to actually register the outputs.
So we'll just call this let's maybe say host name underscore output doesn't
actually matter
the name itself so long as you reference it when you go to Prince and the next
task will
simply be to print the results.
Cool, cool, cool.
So what I'm going to do now is use the debug module and I will use the var
keyword and
the variable I'm going to print out is going to be host name underscore outputs
.
So let's press escape colon wq to write and quickly I say what I can do is just
say Ansible WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
say Ansible
playbook play to dot yml to run the playbook ordinarily.
And as we can see the playbook executes and in order to actually see the output
here, let's
actually just get the STD out attributes.
That's a good call actually.
So let's go in and just say dot STD out so that will give us only the actual
result of
the commands which is what we see right here.
So as we can see here nothing special at all about this regular old playbook.
It's just running as we are the gnarly would let's now try to run it via Ans
ible navigator.
So if I say Ansible navigator run and for now let's just specify the name of WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
So if I say Ansible navigator run and for now let's just specify the name of
the playbook.
Okay, so no other options.
Okay, if I hit enter here, look at what's actually happening.
We go into the text user interface.
This is what I'm talking about.
It might look a little bit strange at first.
So we can actually see here the progress is complete.
We have four tasks that is two tasks for two hosts.
So two times two is four.
And if you want to go in and see more information, we just look at the
numerical values on the
left hand side, we see the value zero.
So if I just press zero, we go into playbook two. WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
So if I just press zero, we go into playbook two.
Now we see everything ordered once again.
So if I want to see the result of the first task, which was us running the Ans
ible built
in command module against the blue box, I can press the corresponding value
zero.
And look at this right here, we actually get all of the information which we
can just scroll
through to that everything right here.
And again, we can actually see that STD outs that is the value end up parsing
in the next
task.
So if I press escape, if I press the value one, this now gives us the results WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
So if I press escape, if I press the value one, this now gives us the results
of the first
task for the yellow box.
And no surprise is there.
If we scroll on down, let's look at the STD out attribute.
We can see the value is indeed yellow box.
And again, we press escape.
If we go to number two, this is going to give us the result of the second task,
the debug
task for the blue box.
And look at this scrolling on down.
The task is called print results.
And we actually see the result of the variable here hosting underscore output
dot STD out
resolves to blue box as expected.
And again, no surprises pressing three.
We get the same result this time for the yellow box. WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
We get the same result this time for the yellow box.
Now, like I say, that is always seeing the text user interface.
If I want to get the same type of output, as I would see with my regular Ans
ible playbook,
I can just use that dash inflag and specify that I want STD out.
So if I hit enter, run the playbook, give it a moment and look at this right
here.
This is much more as we would expect to see via Ansible playbooks.
The difference is, is that this time the playbook was run within an execution
environment.