So now let's go and take a look at this NMCLI module and you know the best
place to go is
to the actual documentation. So with that said let's bring up a browser window.
So if you just
happen to search for Ansible NMCLI module at the very top here we see this
particular link,
let's click on it. Now as it says at the very top here this module is part of
the community
general collection meaning that it is not going to be automatically on your
system.
As you can see right here not included in Ansible Core. However we know as we WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
As you can see right here not included in Ansible Core. However we know as we
saw before when we
want to install a particular collection we can just simply use Ansible Galaxy
and it is this
particular command here which is going to give us access to the community
general collection
and access to the NMCLI module. So if we just go down here let's see what it
actually does then.
Well as we can see it's going to allow us to manage network devices no
surprises there that is
exactly what we would expect but more specifically it's going to allow us to
create modify manage
various connections and device types so that would include things like Ethernet WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
various connections and device types so that would include things like Ethernet
, it would include
things like bonds which is using multiple links together as well as some more
slightly advanced
networking concepts that we don't have to worry about things such as VLANs
virtual LANs.
Now as we can see here as per the requirements we're going to have to ensure
that network manager
is installed on any system we want to use the NMCLI module but as we happen to
have a rail system
this will automatically be installed. So if we go to the actual parameters here
we can see exactly
what this particular utility can do. Now scrolling on down this one is very WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
what this particular utility can do. Now scrolling on down this one is very
very important.
Con underscore name we can see here it's going to allow us to supply a string
value
and this should be the name used to call the connection. Now the important part
here is that
this is a required option meaning that if we want to happen to use the NMCLI
module this particular
option absolutely has to be provided. If we want to specify some type of DNS
servers well we can
supply the DNS for option the for option it's actually going to correlate to WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
supply the DNS for option the for option it's actually going to correlate to
IPv4 based configurations
so that could be things such as you know GIGO's public DNS server like 8.8.8.8
and 8.8.8.4.4
that type of thing or perhaps even maybe a private IP address that you have on
your own local network
just be aware as that if you want to specify some type of DNS configuration it
's going to take a
list as a value and the constituent values are going to be made up of strings.
As you can see we
also have DNS 6 allowing us to specify IPv6 addresses for the DNS servers. WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
also have DNS 6 allowing us to specify IPv6 addresses for the DNS servers.
Similarly when we happen
to define a particular network connection on an interface we can use the IPv4
option
allowing us to once again specify a list of IPv4 addresses that we want to
assign
to this particular interface. Same thing is true here when it comes to IPv6 we
simply use the IPv6
parameter. Now if you want to add some type of static routes in your interface
configuration
well for IPv4 based routes you would simply use the keyword routes for once WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
well for IPv4 based routes you would simply use the keyword routes for once
again specifying a list
of options and the elements are going to be in string format so in this case
here look at this
particular example. In the case here we have what is known as side annotation
this part here is the
actual network we're trying to reach so we can actually see the network ID of
192.0.3.0
with its network mask of a /24 and what we're effectively seeing here is that
if you want to get
to this particular network you should actually send the packet to this WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
to this particular network you should actually send the packet to this
particular destination here
the IP address of 192.0.2.1 so quite simply we define the network we want to go
to with its mask
and then immediately after we specify what our next hop should be towards that
particular destination
this here constitutes the static routes which is what we're going to define
right here so really
whether it's if you're configuring static routes or if you're configuring Wi-Fi
whatever it may be
if you want to learn how to utilize this via nmcli via answerable all of the WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
if you want to learn how to utilize this via nmcli via answerable all of the
details are going to
be found within this documentation now if we just scroll down a little bit
further we're actually
going to see some examples so as per the documentation we have this example
right here take this part
okay what is going on here well as we can see here we're targeting particular
hosts within the
inventory and then we define our task now this part here is really just
ensuring that the device
we're trying to manage has all of the necessary libraries that are needed in
order to operate
we as Red Hat Enterprise Linux users don't have to worry about such a thing WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
we as Red Hat Enterprise Linux users don't have to worry about such a thing
okay so let's just move
on to this part here we'll begin actually using the module itself so in this
part here all we're
doing is defining a task name and then we can see the actual use of the modules
here as we can see
here we have the fully qualified collection name and then intended within we
have particular values
so notice straight away we're always going to see this con underscore name why
is that because as
we saw as per the documentation this is going to be required in order for the WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
we saw as per the documentation this is going to be required in order for the
module to operate
now in this case here it's just being populated with some variable values but
you can hardcode
them if you so wish and then we have some other values we have that ip4 value
we just looked at
again this is going to be populated with some type of variable value in the
example and then we have
the gw4 value if you happen to check the documentation this is going to be the
configuration for the
default gateway pretty much the place you want to send packets to when we're
trying to reach a
remote network so this is going to be some type of routing device okay and WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
remote network so this is going to be some type of routing device okay and
again because it's gw4
as you can expect the configuration supplied here is going to be an ipv4
address once again the
example provides a variable value but it can be hardcoded then we get to this
part here or with
items now if you recall when we discussed the concept of looping this here was
an older
convention in order to invoke a loop nowadays it's just recommended you just
use the loop keyword
so that's one thing i just want to highlight in this documentation you may see
many many examples
using with underscore items in your mind just conceptualize that as using the WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
using with underscore items in your mind just conceptualize that as using the
loop keywords
so really scrolling through the documentation we're going to see a wide variety
of examples
the very last thing i want to do is to ensure that we have the nncli module
available to us
so how do we get that let's scroll up to the very top once again as we can see
as per the
documentation we simply use this particular command so let's just copy this
right here okay
to copy you and then on the answerable control nodes we can just simply paste WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
to copy you and then on the answerable control nodes we can just simply paste
in the command
and then hit enter now in my case here i have already installed this particular
collection but
if you have not the installation will begin and if you give it a few moments
you will also have
access to the answerable community general collection