WEBVTT

1
00:00.000 --> 00:04.560
So one of the most important things that we do as Linux administrators is the

2
00:04.560 --> 00:06.640
management of services.

3
00:06.640 --> 00:10.480
So this could be services such as your SSH connection, perhaps maybe it's an

4
00:10.480 --> 00:12.640
engine X web server, that type of thing.

5
00:12.640 --> 00:17.040
Whatever it may be, we want to ensure that services start as expected and they

6
00:17.040 --> 00:21.440
can be rebooted as expected, shut down as expected, that type of thing.

7
00:21.440 --> 00:25.360
Now just like with anything we do on Linux, this can be a rather tedious task

8
00:25.360 --> 00:29.280
if you have to do it manually by logging into hundreds or maybe even thousands

9
00:29.280 --> 00:29.840
of servers

10
00:29.840 --> 00:34.490
individually and as such we want to use Ansible to invoke automation to make
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

10
00:29.840 --> 00:34.490
individually and as such we want to use Ansible to invoke automation to make

11
00:34.490 --> 00:36.640
this task a lot more manageable.

12
00:36.640 --> 00:40.400
So the good thing to note is that with respect to our services Ansible actually

13
00:40.400 --> 00:43.040
has a dedicated services module.

14
00:43.040 --> 00:46.690
So with that said, why don't we dive in and look at what this actually does for

15
00:46.690 --> 00:47.120
us.

16
00:47.120 --> 00:50.450
So what are we going to do? You guessed it, we'll go directly to the Ansible

17
00:50.450 --> 00:51.280
documentation.

18
00:51.280 --> 00:55.700
So if you search for Ansible service module and click this link here and as we

19
00:55.700 --> 00:58.080
can see here, this is part of the Ansible core collection.

20
00:58.080 --> 01:00.400
So it's going to be automatically available for us.
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

20
00:58.080 --> 01:00.400
So it's going to be automatically available for us.

21
01:00.400 --> 01:04.920
And you'll notice as per the synopsis, this is actually a generic module,

22
01:04.920 --> 01:08.320
meaning that it doesn't just operate only on system D services.

23
01:08.320 --> 01:12.400
We could have services managed by Upstart or say for example, SysFiannet, that

24
01:12.400 --> 01:13.120
type of thing.

25
01:13.120 --> 01:17.560
And what I will say is that we also do have a dedicated system D module which

26
01:17.560 --> 01:18.480
you can also use.

27
01:18.480 --> 01:22.510
Just like as it says here below, this particular module is a proxy for more

28
01:22.510 --> 01:24.320
specific service manager modules,

29
01:24.320 --> 01:28.160
such as just like I said here, the Ansible built in system D module.

30
01:28.160 --> 01:32.320
Now in my own personal preference, I just like to use the service module and
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

30
01:28.160 --> 01:32.320
Now in my own personal preference, I just like to use the service module and

31
01:32.320 --> 01:34.480
have Ansible work of the details under the hood.

32
01:34.480 --> 01:37.160
So that is what we're going to do in this particular video.

33
01:37.160 --> 01:41.380
Now again, scrolling on down, notice the name parameter here happens to be a

34
01:41.380 --> 01:42.320
required field.

35
01:42.320 --> 01:45.240
We have to specify the name of the service we want to be managing.

36
01:45.240 --> 01:48.800
And an important option here is the state parameter.

37
01:48.800 --> 01:54.240
So the options we have here are reloaded, restarted, started and stopped.

38
01:54.240 --> 01:57.550
Now another important parameter we want to quickly look at is the enabled

39
01:57.550 --> 01:58.400
parameter.

40
01:58.400 --> 02:02.670
This one right here, this is pretty much whether or not the service should
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

40
01:58.400 --> 02:02.670
This one right here, this is pretty much whether or not the service should

41
02:02.670 --> 02:04.360
start on but this one here though,

42
02:04.360 --> 02:05.840
it's just simply a billion value.

43
02:05.840 --> 02:08.600
Is it going to be true or is it going to be false?

44
02:08.600 --> 02:14.000
Now notice here, it says at least one of state and enabled are required.

45
02:14.000 --> 02:18.730
So basically, when you use this module, you do not have to explicitly include

46
02:18.730 --> 02:21.280
the enabled parameter or the state parameter,

47
02:21.280 --> 02:23.120
but you have to include one or the other.

48
02:23.120 --> 02:27.790
So the name is required and either or enabled or state and if you so wish, you

49
02:27.790 --> 02:31.840
can include both the state and the enabled parameter.
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

49
02:27.790 --> 02:31.840
can include both the state and the enabled parameter.

50
02:31.840 --> 02:34.480
So let's go and see how this actually operates then.

51
02:34.480 --> 02:39.520
So let me just create an example called service_example.ymail.

52
02:39.520 --> 02:43.320
I'm going to insert mode, have my three hyphens, I'll give it a name, I'll just

53
02:43.320 --> 02:45.440
say play to test the service module.

54
02:45.440 --> 02:48.460
Home, I'm going to target, I will target the all group and I'm going to set my

55
02:48.460 --> 02:50.800
gather facts to be the value false.

56
02:50.800 --> 02:55.420
Now I'm going to define my tasks and the name of the task is going to be

57
02:55.420 --> 02:57.040
installing 80PD.

58
02:57.040 --> 03:00.410
Now what I'm going to do here right now is I'm going to use the Ansible built-
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

58
02:57.040 --> 03:00.410
Now what I'm going to do here right now is I'm going to use the Ansible built-

59
03:00.410 --> 03:03.360
in DNF module, which is used to install services.

60
03:03.360 --> 03:08.280
And the service I want to install is going to be 80PD and I'm going to ensure

61
03:08.280 --> 03:11.040
that the state is present on the system.

62
03:11.040 --> 03:15.380
Now right now, we're not using the actual service module, we're just using the

63
03:15.380 --> 03:17.360
DNF module to install a service.

64
03:17.360 --> 03:21.440
Little bit different, however, immediately after once we have that particular

65
03:21.440 --> 03:25.150
package, we want to manage the service itself and that is when we're going to

66
03:25.150 --> 03:26.960
use the service module.

67
03:26.960 --> 03:31.120
So the name of this task will just be to check the 80PD as operational.
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

67
03:26.960 --> 03:31.120
So the name of this task will just be to check the 80PD as operational.

68
03:31.120 --> 03:35.070
And now I'm going to use that service module so Ansible dot built-in dot

69
03:35.070 --> 03:35.680
service.

70
03:35.680 --> 03:39.340
And like I say, I need to specify a name and the name of the service is going

71
03:39.340 --> 03:40.280
to be 80PD.

72
03:40.280 --> 03:43.960
And I need to specify either the state or the enable parameter.

73
03:43.960 --> 03:46.080
Now in my case here, I'm going to choose both.

74
03:46.080 --> 03:50.820
I will say state is going to be that it started and I'll also have enabled set

75
03:50.820 --> 03:51.520
to true.

76
03:51.520 --> 03:54.660
So that means that it should be running and it will be configured such that

77
03:54.660 --> 03:56.800
when the system is ever rebutted,

78
03:56.800 --> 04:00.160
the service 80PD is automatically going to start.
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

78
03:56.800 --> 04:00.160
the service 80PD is automatically going to start.

79
04:00.160 --> 04:01.600
So let's check this out then.

80
04:01.600 --> 04:06.560
So also Ansible, service example dot yml and to enter, give it a moment.

81
04:06.560 --> 04:08.480
And we can see the change has been applied.

82
04:08.480 --> 04:11.280
Now we're running the service module to check that it's operational.

83
04:11.280 --> 04:13.200
And we can see the playbook has finished.

84
04:13.200 --> 04:15.840
So what I will do now is go to my devices.

85
04:15.840 --> 04:22.110
So if I say systemctl status on 80PD, notice it started 43 seconds ago by Ans

86
04:22.110 --> 04:22.400
ible.

87
04:22.400 --> 04:26.430
It is now up and running and the service is enabled, meaning that if I happen

88
04:26.430 --> 04:26.560
to

89
04:26.560 --> 04:29.600
rebut the server, it will begin to restart once again.

90
04:29.600 --> 04:32.960
Now if you want to change the values here, what I can do is go and modify the
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

90
04:29.600 --> 04:32.960
Now if you want to change the values here, what I can do is go and modify the

91
04:32.960 --> 04:33.600
playbook.

92
04:33.600 --> 04:36.960
What I could do is go in and change the state to maybe be stopped.

93
04:36.960 --> 04:40.240
But notice I'm still leaving the enabled value to true.

94
04:40.240 --> 04:41.200
So check this out now.

95
04:41.200 --> 04:44.880
Let's see Ansible playbook, service example dot yml hit enter.

96
04:44.880 --> 04:47.040
80PD is already installed.

97
04:47.040 --> 04:48.880
So we're basically going to skip that task.

98
04:48.880 --> 04:52.800
But we can see we have a change on the status of 80PD.

99
04:52.800 --> 04:55.040
So let's go back to our server right now.

100
04:55.040 --> 04:59.600
If I just clear the screen and arrow up, notice the status is now active and

101
04:59.600 --> 05:00.000
dead.
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

102
05:00.000 --> 05:03.280
It was stopped 14 seconds ago, but it still is indeed enabled.

103
05:03.280 --> 05:07.680
And once again, if I go back to my settings here and change enabled to false,

104
05:07.680 --> 05:08.560
we run the playbook.

105
05:08.560 --> 05:10.160
Now the playbook completes.

106
05:10.160 --> 05:13.680
Let's maybe go to the blue box this time just for a little bit of variation,

107
05:13.680 --> 05:19.680
systemctl status on 80PD. We can see the service as an active and dead and that

108
05:19.680 --> 05:20.000
has

109
05:20.000 --> 05:21.200
also been disabled.
