So friends, how about we go and try out this NMCLI module then.
Okay, so how about we kick off and begin writing a playbook then.
So let's just call this one play1.yml.
Now inside of here, what I will do is go into insert mode
and I'm going to start with, you guessed my three hyphens at the top to denote
a yaml file.
And now I'm going to give this playbook a name.
So the name here is going to be super duper original.
It's going to be play one testing the NMCLI module.
Okay, now what I want to do is I want to decide which host do I want to target WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
Okay, now what I want to do is I want to decide which host do I want to target
with this particular playbook.
So in my case here, I will just target all of the devices in my inventory,
which is going to be my blue box and my yellow box.
Now the next thing I want to do is to decide, do I want to gather facts about
both of these devices before I actually use this particular module?
Well, in my case here, I don't actually need that information.
So to speed things up, I will just set gather facts to be the billion value of
false.
Here is where I'm going to define my tasks. WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
Here is where I'm going to define my tasks.
So let's give this task a name and I will just call it task one, simple module
test.
Okay, now recall when we happen to use the module,
we want to specify the fully qualified collection name.
Now in this case here, it's going to be community dot general dot nmcli.
Now intended within here, what I want to do is to define my parameters.
Now one parameter we absolutely must specify is the connection name.
Now the connection name here is going to be which interface am I going to be WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
Now the connection name here is going to be which interface am I going to be
targeting?
So if I say con name and just type in something random, such as blah, blah,
blah, then we're going to find that the module is going to fail.
And did instead we want to target a working interface on one of our devices
or rather on all of the devices we want to target.
So if I go back to my blue box, let's maybe say, and let's pull up a terminal.
So if I just say IP adder, we can see the ethernet interface is called ENS at
one
sector. Now that happens to be present on this particular machine, WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
as well as on the yellow box, once again, open up a terminal, do an IP adder.
This is also ENS one sector.
So what that means is that within my actual playbook, what I can do is just
target
ENS 160 with a hard coded value.
Now if there happened to be some type of variation, perhaps maybe you were
contacting
or connecting to maybe 500 devices, not every device is necessarily going to
have the same
interface name. Therefore, what you could do, in fact, what you probably should
be doing,
as opposed to hard coding these, we could be using our variable values with our WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
as opposed to hard coding these, we could be using our variable values with our
double curly
braces and just simply calling in the values as needed for each host within the
inventory.
Like I say, it's just a lab environment. They are all the same.
So I'm just going to leave it hard coded to keep things nice and simple.
Now what I want to think about is what type of interface is this connection?
Is it a look back address?
Well, in this case, it is not. It is indeed instead an ethernet connection.
And as such, I want to tell the module about that. WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
So once again, where am I getting these keywords from?
It's all in the documentation that we explored in a previous video.
That is why this is so important to understand that.
So specify ethernet and what is I want to actually configure.
So as we saw, there are a whole bunch of options.
In the case here, let's maybe just go and start off with a DNS setting.
Now recall, when it comes to the NMCLI module, we can specify a DNS4 option,
which is going to allow us to provide IPv4 based addresses. WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
which is going to allow us to provide IPv4 based addresses.
Or if I so wish, I can use the option DNS6 for the corresponding IPv6.
In my case here, IPv4 is easy enough. So let's stick with that.
So we say DNS4. So as per the documentation, for this particular parameter,
we need to supply a list of values. So let's go and do that then.
So let's have our hyphen to denote the very first element within our list.
And the value I will provide will be 8.8.8.8.
Now I will provide a second DNS server just for good measure.
And this time I will say 8.8.4.4. WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
And this time I will say 8.8.4.4.
Now I want this connection to be present, so I will say state is present.
And with that, what I can do is just press escape colon, WQ to writing quit.
And we should be able to run the playbooks. So all I will do here
is just ensure I have connectivity to my blue box, which I do,
as well as to my yellow box, which I do. And with that said, what I can now do
is just say answerable hyphen playbook, play1.yml and hit enter.
So give it a moment. And as we can see here, the task has apparently completed. WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
So give it a moment. And as we can see here, the task has apparently completed.
So what we're going to do is go and verify that the changes did indeed take
effect.
So what I can do is go to the yellow box here.
So if I go to my device and I say IP adder, it might not be apparent that any
configurations have actually changed. However, if I say nmcli,
con show, we can see my connections, the connection we are interested in,
the one we modified was ens 160. So let's be a little bit more specific
and target that particular device. And now we're going to see all of the
configurations within this particular interface. Now if I press the space bar WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
configurations within this particular interface. Now if I press the space bar
and just go down to ipv4.dns, look at this right here.
We actually have the configurations that we actually specified within our
playbook. And also, if we slide on over to our other device, the blue box,
let me just briefly log in. And once again, let me clear the screen, I will say
nmcli,
con show, ens 160 and hit enter, hit the space bar.
And just like we saw before, we also have our ipv4 dns configurations to point WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
And just like we saw before, we also have our ipv4 dns configurations to point
to the IP
addresses, 8.8.8.8 and 8.8.4.4. Now the cool thing is with these
Ansible modules, notice we actually have a change that has been configured.
If I rerun the same playbook once again, look at this right here.
Now it says we have not made any changes. That is because these modules, like I
said before,
they actually have the advantage of being item potants.
Now however, if I go in and I'm making modification to that particular playbook
,
let's go in one more time, let's go into insert modes, let's maybe add one of WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
let's go in one more time, let's go into insert modes, let's maybe add one of
192.
168. Let's just do 1.1 and I write and quit.
If I arrow up and rerun the playbook, because we have made a new change, the
change has been
applied. We can see that in the summary. And now if I go to the blue box, let's
clear the screen,
arrow up, rerun the same command, press space bar to go down. We can indeed see
we have added
that third configuration. And the same thing is true on the yellow box device.