WEBVTT

1
00:00.000 --> 00:04.560
So friends, how about we go and try out this NMCLI module then.

2
00:04.560 --> 00:08.000
Okay, so how about we kick off and begin writing a playbook then.

3
00:08.000 --> 00:11.440
So let's just call this one play1.yml.

4
00:11.440 --> 00:14.080
Now inside of here, what I will do is go into insert mode

5
00:14.080 --> 00:17.680
and I'm going to start with, you guessed my three hyphens at the top to denote

6
00:17.680 --> 00:18.960
a yaml file.

7
00:18.960 --> 00:20.880
And now I'm going to give this playbook a name.

8
00:20.880 --> 00:23.680
So the name here is going to be super duper original.

9
00:23.680 --> 00:28.320
It's going to be play one testing the NMCLI module.

10
00:28.320 --> 00:32.160
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

10
00:28.320 --> 00:32.160
Okay, now what I want to do is I want to decide which host do I want to target

11
00:32.160 --> 00:33.680
with this particular playbook.

12
00:33.680 --> 00:37.920
So in my case here, I will just target all of the devices in my inventory,

13
00:37.920 --> 00:41.120
which is going to be my blue box and my yellow box.

14
00:41.120 --> 00:45.920
Now the next thing I want to do is to decide, do I want to gather facts about

15
00:45.920 --> 00:49.760
both of these devices before I actually use this particular module?

16
00:49.760 --> 00:53.440
Well, in my case here, I don't actually need that information.

17
00:53.440 --> 00:57.840
So to speed things up, I will just set gather facts to be the billion value of

18
00:57.840 --> 00:58.160
false.

19
00:58.160 --> 01:00.480
Here is where I'm going to define my tasks.
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

19
00:58.160 --> 01:00.480
Here is where I'm going to define my tasks.

20
01:00.480 --> 01:05.120
So let's give this task a name and I will just call it task one, simple module

21
01:05.120 --> 01:05.680
test.

22
01:05.680 --> 01:09.760
Okay, now recall when we happen to use the module,

23
01:09.760 --> 01:13.040
we want to specify the fully qualified collection name.

24
01:13.040 --> 01:20.240
Now in this case here, it's going to be community dot general dot nmcli.

25
01:20.240 --> 01:24.800
Now intended within here, what I want to do is to define my parameters.

26
01:24.800 --> 01:29.200
Now one parameter we absolutely must specify is the connection name.

27
01:29.200 --> 01:32.560
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

27
01:29.200 --> 01:32.560
Now the connection name here is going to be which interface am I going to be

28
01:32.560 --> 01:33.200
targeting?

29
01:33.200 --> 01:37.440
So if I say con name and just type in something random, such as blah, blah,

30
01:37.440 --> 01:40.720
blah, then we're going to find that the module is going to fail.

31
01:40.720 --> 01:45.440
And did instead we want to target a working interface on one of our devices

32
01:45.440 --> 01:48.240
or rather on all of the devices we want to target.

33
01:48.240 --> 01:52.640
So if I go back to my blue box, let's maybe say, and let's pull up a terminal.

34
01:52.640 --> 01:56.980
So if I just say IP adder, we can see the ethernet interface is called ENS at

35
01:56.980 --> 01:57.200
one

36
01:57.200 --> 02:00.000
sector. Now that happens to be present on this particular machine,
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

37
02:00.000 --> 02:04.560
as well as on the yellow box, once again, open up a terminal, do an IP adder.

38
02:04.560 --> 02:07.360
This is also ENS one sector.

39
02:07.360 --> 02:11.050
So what that means is that within my actual playbook, what I can do is just

40
02:11.050 --> 02:11.840
target

41
02:11.840 --> 02:13.920
ENS 160 with a hard coded value.

42
02:13.920 --> 02:17.360
Now if there happened to be some type of variation, perhaps maybe you were

43
02:17.360 --> 02:17.920
contacting

44
02:17.920 --> 02:23.120
or connecting to maybe 500 devices, not every device is necessarily going to

45
02:23.120 --> 02:23.680
have the same

46
02:23.680 --> 02:28.000
interface name. Therefore, what you could do, in fact, what you probably should

47
02:28.000 --> 02:28.560
be doing,

48
02:28.560 --> 02:32.960
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

48
02:28.560 --> 02:32.960
as opposed to hard coding these, we could be using our variable values with our

49
02:32.960 --> 02:33.440
double curly

50
02:33.440 --> 02:38.430
braces and just simply calling in the values as needed for each host within the

51
02:38.430 --> 02:39.200
inventory.

52
02:39.200 --> 02:41.920
Like I say, it's just a lab environment. They are all the same.

53
02:41.920 --> 02:45.840
So I'm just going to leave it hard coded to keep things nice and simple.

54
02:45.840 --> 02:50.000
Now what I want to think about is what type of interface is this connection?

55
02:50.000 --> 02:51.760
Is it a look back address?

56
02:51.760 --> 02:56.720
Well, in this case, it is not. It is indeed instead an ethernet connection.

57
02:56.720 --> 03:00.000
And as such, I want to tell the module about that.
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

58
03:00.000 --> 03:02.320
So once again, where am I getting these keywords from?

59
03:02.320 --> 03:05.760
It's all in the documentation that we explored in a previous video.

60
03:05.760 --> 03:08.400
That is why this is so important to understand that.

61
03:08.400 --> 03:12.800
So specify ethernet and what is I want to actually configure.

62
03:12.800 --> 03:15.920
So as we saw, there are a whole bunch of options.

63
03:15.920 --> 03:21.600
In the case here, let's maybe just go and start off with a DNS setting.

64
03:21.600 --> 03:27.120
Now recall, when it comes to the NMCLI module, we can specify a DNS4 option,

65
03:27.120 --> 03:30.480
which is going to allow us to provide IPv4 based addresses.
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

65
03:27.120 --> 03:30.480
which is going to allow us to provide IPv4 based addresses.

66
03:30.480 --> 03:35.520
Or if I so wish, I can use the option DNS6 for the corresponding IPv6.

67
03:35.520 --> 03:39.680
In my case here, IPv4 is easy enough. So let's stick with that.

68
03:39.680 --> 03:44.400
So we say DNS4. So as per the documentation, for this particular parameter,

69
03:44.400 --> 03:48.480
we need to supply a list of values. So let's go and do that then.

70
03:48.480 --> 03:52.400
So let's have our hyphen to denote the very first element within our list.

71
03:52.400 --> 03:55.920
And the value I will provide will be 8.8.8.8.

72
03:55.920 --> 03:59.520
Now I will provide a second DNS server just for good measure.

73
03:59.520 --> 04:03.040
And this time I will say 8.8.4.4.
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

73
03:59.520 --> 04:03.040
And this time I will say 8.8.4.4.

74
04:03.040 --> 04:07.200
Now I want this connection to be present, so I will say state is present.

75
04:07.200 --> 04:11.920
And with that, what I can do is just press escape colon, WQ to writing quit.

76
04:11.920 --> 04:14.960
And we should be able to run the playbooks. So all I will do here

77
04:14.960 --> 04:18.640
is just ensure I have connectivity to my blue box, which I do,

78
04:18.640 --> 04:23.520
as well as to my yellow box, which I do. And with that said, what I can now do

79
04:23.520 --> 04:27.920
is just say answerable hyphen playbook, play1.yml and hit enter.

80
04:27.920 --> 04:32.240
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

80
04:27.920 --> 04:32.240
So give it a moment. And as we can see here, the task has apparently completed.

81
04:32.240 --> 04:36.490
So what we're going to do is go and verify that the changes did indeed take

82
04:36.490 --> 04:36.960
effect.

83
04:36.960 --> 04:39.280
So what I can do is go to the yellow box here.

84
04:39.280 --> 04:43.440
So if I go to my device and I say IP adder, it might not be apparent that any

85
04:43.440 --> 04:48.000
configurations have actually changed. However, if I say nmcli,

86
04:48.000 --> 04:51.760
con show, we can see my connections, the connection we are interested in,

87
04:51.760 --> 04:56.080
the one we modified was ens 160. So let's be a little bit more specific

88
04:56.080 --> 04:59.680
and target that particular device. And now we're going to see all of the

89
04:59.680 --> 05:04.320
configurations within this particular interface. Now if I press the space bar
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

89
04:59.680 --> 05:04.320
configurations within this particular interface. Now if I press the space bar

90
05:04.320 --> 05:09.280
and just go down to ipv4.dns, look at this right here.

91
05:09.280 --> 05:13.040
We actually have the configurations that we actually specified within our

92
05:13.040 --> 05:17.760
playbook. And also, if we slide on over to our other device, the blue box,

93
05:17.760 --> 05:20.990
let me just briefly log in. And once again, let me clear the screen, I will say

94
05:20.990 --> 05:21.840
nmcli,

95
05:21.840 --> 05:26.560
con show, ens 160 and hit enter, hit the space bar.

96
05:26.560 --> 05:31.200
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

96
05:26.560 --> 05:31.200
And just like we saw before, we also have our ipv4 dns configurations to point

97
05:31.200 --> 05:31.760
to the IP

98
05:31.760 --> 05:37.520
addresses, 8.8.8.8 and 8.8.4.4. Now the cool thing is with these

99
05:37.520 --> 05:41.680
Ansible modules, notice we actually have a change that has been configured.

100
05:41.680 --> 05:45.520
If I rerun the same playbook once again, look at this right here.

101
05:45.520 --> 05:50.160
Now it says we have not made any changes. That is because these modules, like I

102
05:50.160 --> 05:51.040
said before,

103
05:51.040 --> 05:54.320
they actually have the advantage of being item potants.

104
05:54.320 --> 05:58.210
Now however, if I go in and I'm making modification to that particular playbook

105
05:58.210 --> 05:58.320
,

106
05:58.320 --> 06:01.840
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

106
05:58.320 --> 06:01.840
let's go in one more time, let's go into insert modes, let's maybe add one of

107
06:01.840 --> 06:02.640
192.

108
06:02.640 --> 06:06.720
168. Let's just do 1.1 and I write and quit.

109
06:06.720 --> 06:10.720
If I arrow up and rerun the playbook, because we have made a new change, the

110
06:10.720 --> 06:11.440
change has been

111
06:11.440 --> 06:14.560
applied. We can see that in the summary. And now if I go to the blue box, let's

112
06:14.560 --> 06:15.200
clear the screen,

113
06:15.200 --> 06:19.280
arrow up, rerun the same command, press space bar to go down. We can indeed see

114
06:19.280 --> 06:20.160
we have added

115
06:20.160 --> 06:24.960
that third configuration. And the same thing is true on the yellow box device.
