So friends, before we wrap up, let's do a little further exploration utilizing
our system role.
So what I will do is I will create a new playbook, let's just call this Play3.Y
ML.
Let's go into insert mode, have our three hyphens at the top as per usual.
Get the playbook a name and we'll call the name Play3.Tada, really, really
interesting.
As we know, my names are always that good.
And again, we're going to target the host of the all group.
We'll set gather facts to be false.
And once the game will define our variables.
So the network provider, you already know is going to be N.M. WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
So the network provider, you already know is going to be N.M.
No surprises there.
The network connection, we're going to have a name.
Once again, we're going to specify, we're going to target the ENS 160 interface
.
Now, of course, in the real world, you may have many more interfaces.
You shouldn't always be operating on what is in my case here, my management
interface.
We just talked about that in the previous video.
But nevertheless, as they want interface, which I do have active.
So because of that, I'm just going to continue the lab on it.
So what we'll do is I'll specify the type is going to be Ethernet.
And let's maybe add in some static routing information. WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
And let's maybe add in some static routing information.
So what I will do is as per the documentation, if you follow along,
you can see we happen to have the IP command.
And in Dented Within, we can specify the route to take.
Now, the routes can actually be specified as a list because, of course, we can
have more
than one route we can figure.
So we'll have my list object and I will specify that the key we're going to use
is going to be the network.
So which network do we want to actually have here?
So let's maybe say we want to go to, let's go with the, WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
So let's maybe say we want to go to, let's go with the,
well, I don't know, let's say 192.168.33.0 network.
Now we specify what the prefix mass should actually be.
So this should be a slash 24 mask.
And now we specify what should be the next hop to get to that particular
network.
So we specify the gateway.
In this case here, it's going to be let's maybe go with 192.168.
Well, I don't know, let's just say 1.1.
OK, keep it really simple.
And let's maybe add another route into the equation here.
So we'll just say network.
So this network can be 10.1500. WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
So this network can be 10.1500.
We'll give it a prefix of a slash 16 mask.
And the gateway on this one, let's just maybe give it 192.168.2.1.
It doesn't actually matter.
Like I said, we're just testing things out.
And now at the same level of indentation as our vars, we specify our roles.
And it's going to be the rail system role.network.
Now again, if we want to make the changes be applied straight away,
we're going to have to reload the connection.
Now in the case here, we actually shouldn't drop the connection.
That's 10.
Can you think why?
Well, it's actually acting on the interface, which is effectively the WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
Well, it's actually acting on the interface, which is effectively the
management interface.
We're not actually modifying the interface's IP addressing configuration itself
.
We're just modifying some static routes associated with that interface.
So the IP address is on each device for the ENS 160 interface should stay the
same
on both of the targeted devices.
What I want to do is I want to specify some tasks.
Okay.
Now we can get the task in name.
Again, something simple, nice and descriptive.
And we're going to use the answer will built in command module.
And again, the command is going to be in our case, nmcli, WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
And again, the command is going to be in our case, nmcli,
corn up.
And in our case, it's going to be ENS 160.
Now think about it like this.
What have you happened to be dealing with more than one interface right here?
Or perhaps maybe say the interface was a variable value.
It wasn't the exact same interface all the time.
Would it be a good idea therefore to actually be hard coding this particular
value?
Well, of course, that's not going to make any sense.
So what we actually should do is we should just reference a variable value here WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
So what we actually should do is we should just reference a variable value here
,
meaning that if we happen to make a change to the value here,
we don't have to go and repeat that exact same change down here.
Just by simply referencing the variable, we change it one time here.
And it's going to be applied throughout the playbook itself.
So the question is, what is the variable value we're trying to actually
ascertain right here?
Well, think about it. It's going to be in our network connections key right
here.
And indented within, we actually want to target the name key.
Now think about it like this though.
We're not just targeting the name key.
We actually have a list element. WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
We actually have a list element.
See that here?
Now, which element within the list are we targeting?
We're targeting the zero element, which is going to be the very first element
within the list.
So this is going to give us access to this particular element here, albeit a
nested element.
But now we have access to this object. We can therefore grab the value of the
name key
to return the actual name of the interface you want to target.
So the way that's actually going to shake out right here is if I go into insert
mode,
and I'll have my double color braces, which is going to allow us to have a
variable value.
And the first object I want to get is going to be the network underscore WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
And the first object I want to get is going to be the network underscore
connection objects.
And then I want to take the first element within the array,
like I say, remember the array object right here.
And then I can say dot name, which is going to call the name key.
So now pretty much if I happen to want to perform this type of operation on a
different interface,
but automatically the different interface is going to be reloaded.
And in fact, before we run this, I should actually spell this correctly.
That should be network connections with an S just to make sure that's actually WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
That should be network connections with an S just to make sure that's actually
correct.
Just try to run the playbooks will run as will play book play three dot YML and
set enter.
So just give it a moment to run through.
As we can see, we've pushed the changes and we have successfully reloaded the
connection.
So if I go to my devices, if I say nmcli, con show, ens one sixties, and let me
just grip
for IPV four dot routes.
Okay. As we can see here within our configuration, we have our IPV four routes.
And more crucially, because we have actually reloaded the connection,
if I just type IP route right here, we can actually see we have specified this WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
if I just type IP route right here, we can actually see we have specified this
particular
configuration here is a 10 dot 15 dot 0 dot 0 slash 16 network.
And we also have the 192 1 6 8 dot 33 dot 0 slash 24 network and sliding on
over to the next device.
Over in the blue box, if we take IP routes, here is the network 10 dot 15 dot 0
dot 0
and below the 192 1 6 8 33 dot 0.
So that's how we can push out some static route configuration using Ansible on
our Linux machines.
Let's now validate what was learned within this scale. WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
Let's now validate what was learned within this scale.