WEBVTT

1
00:00.000 --> 00:04.200
So friends, in this particular video, what we're going to discuss is the

2
00:04.200 --> 00:05.360
utility of

3
00:05.360 --> 00:09.920
Ansible roles. So with that said, let's just dig in. Okay, so let's discuss the

4
00:09.920 --> 00:10.640
whole idea

5
00:10.640 --> 00:15.510
behind the Ansible role. Now, consider this, when you happen to be managing

6
00:15.510 --> 00:17.360
real live environments,

7
00:17.360 --> 00:21.470
whereby you may have many tens or perhaps hundreds or maybe even thousands of

8
00:21.470 --> 00:22.160
devices,

9
00:22.160 --> 00:26.940
this can become really quite complex, even with an automation solution such as

10
00:26.940 --> 00:27.840
Ansible.

11
00:27.840 --> 00:31.010
You know, you have different servers with different requirements, different
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

11
00:27.840 --> 00:31.010
You know, you have different servers with different requirements, different

12
00:31.010 --> 00:31.600
configurations,

13
00:31.600 --> 00:35.820
that type of thing, very quickly, given the scale of things, this can all

14
00:35.820 --> 00:37.440
become very unmanageable,

15
00:37.440 --> 00:41.680
very, very quickly. Now, we know that we can leverage the power of automation,

16
00:41.680 --> 00:42.080
which really

17
00:42.080 --> 00:45.750
does make our life a lot easier than it would be if we had to solve these

18
00:45.750 --> 00:47.040
problems manually.

19
00:47.040 --> 00:51.360
But that doesn't change the fact that management, even with automation,

20
00:51.360 --> 00:55.340
really is quite difficult. Now, what we happen to do with automation, and in

21
00:55.340 --> 00:56.400
the case of Ansible,

22
00:56.400 --> 01:01.180
with our playbooks, is we may actually spend time writing all of these tasks to
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

22
00:56.400 --> 01:01.180
with our playbooks, is we may actually spend time writing all of these tasks to

23
01:01.180 --> 01:01.440
perform

24
01:01.440 --> 01:04.660
particular actions within the network, and then perhaps maybe for one

25
01:04.660 --> 01:06.080
particular device or a

26
01:06.080 --> 01:09.930
subset of devices, we would like to perform a really similar task or maybe a

27
01:09.930 --> 01:10.800
really similar

28
01:10.800 --> 01:16.100
group of tasks, but perhaps with a slight modification to the playbook. So we

29
01:16.100 --> 01:17.760
do not want to have to

30
01:17.760 --> 01:22.160
completely rewrite our entire playbook all over again. And you know, just make

31
01:22.160 --> 01:23.440
small modifications

32
01:23.440 --> 01:27.040
to that particular playbook to suit the new scenario for the new configurations

33
01:27.040 --> 01:28.560
of the new devices.

34
01:28.560 --> 01:33.690
Instead, you might be more tempted to just copy paste an existing playbook and
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

34
01:28.560 --> 01:33.690
Instead, you might be more tempted to just copy paste an existing playbook and

35
01:33.690 --> 01:34.800
begin making those

36
01:34.800 --> 01:39.400
slight modifications as opposed to completely rewriting it. Now, suppose you

37
01:39.400 --> 01:40.080
can do that,

38
01:40.080 --> 01:43.860
but I really would challenge you on that point. So here is the very general

39
01:43.860 --> 01:44.800
rule that I want to

40
01:44.800 --> 01:49.060
suggest to you. If you happen to find yourself copying and pasting many tasks

41
01:49.060 --> 01:50.080
from within your

42
01:50.080 --> 01:54.800
Ansible Playbooks, you should begin considering creating an Ansible role. Now,

43
01:54.800 --> 01:55.520
suppose you happen

44
01:55.520 --> 01:59.520
to have a rather complex Ansible playbook that took you a long time to write,

45
01:59.520 --> 02:00.320
but it is very
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

45
01:59.520 --> 02:00.320
but it is very

46
02:00.320 --> 02:05.020
effective. And more importantly, it is commonly used, okay, or at least parts

47
02:05.020 --> 02:06.080
of the playbook is

48
02:06.080 --> 02:09.230
commonly used. And this can happen for many reasons. Perhaps you may be

49
02:09.230 --> 02:10.400
happened to be in a

50
02:10.400 --> 02:13.700
collaborative environment, maybe someone else wrote a really, really good

51
02:13.700 --> 02:14.800
playbook. But what we want

52
02:14.800 --> 02:19.810
to now do is to take that playbook, make it much less specific, i.e. we

53
02:19.810 --> 02:21.440
actually want to make it

54
02:21.440 --> 02:25.100
more generic. And the whole purpose of this is so that that playbook

55
02:25.100 --> 02:26.560
effectively becomes more

56
02:26.560 --> 02:30.560
modular, as well as more portable, so that it can be just plugged into other
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

56
02:26.560 --> 02:30.560
modular, as well as more portable, so that it can be just plugged into other

57
02:30.560 --> 02:31.920
playbooks quite easily.

58
02:31.920 --> 02:37.040
And crucially, you have the ability to make those necessary small changes. So

59
02:37.040 --> 02:37.840
let's imagine you

60
02:37.840 --> 02:42.570
happen to have, you know, five really well written and complex Ansible tasks.

61
02:42.570 --> 02:43.440
What you could do is

62
02:43.440 --> 02:48.020
just wrap those five tasks into a single role, which as we're going to see as

63
02:48.020 --> 02:49.200
we progress throughout,

64
02:49.200 --> 02:54.250
this skill is really, really easy to call. Quite simply, this particular role

65
02:54.250 --> 02:55.120
that has the ability

66
02:55.120 --> 02:59.410
to do all of these fancy tasks is only going to take up a single line within

67
02:59.410 --> 03:00.800
your playbook. So,
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

67
02:59.410 --> 03:00.800
your playbook. So,

68
03:00.800 --> 03:04.460
perhaps maybe happen to have three roles in your playbook, which is ultimately

69
03:04.460 --> 03:05.520
perhaps maybe calling

70
03:05.520 --> 03:10.050
something like say 25 Ansible tasks. What we're doing here is ultimately making

71
03:10.050 --> 03:11.120
things much more

72
03:11.120 --> 03:15.310
manageable. Now, where I happen to explain the purpose of an Ansible role, one

73
03:15.310 --> 03:16.080
of the closest

74
03:16.080 --> 03:20.750
things I can liken it to is a function in a program. Now, I understand that not

75
03:20.750 --> 03:21.760
everyone watching

76
03:21.760 --> 03:25.600
this particular video is experiencing like maybe say Python programming. But

77
03:25.600 --> 03:26.480
for those of you that

78
03:26.480 --> 03:30.900
do have a little bit experience with Python, really try to conceptualize the
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

78
03:26.480 --> 03:30.900
do have a little bit experience with Python, really try to conceptualize the

79
03:30.900 --> 03:31.760
Ansible role,

80
03:31.760 --> 03:35.440
kind of in the same way you would a Python function. This gives you a nice

81
03:35.440 --> 03:37.360
piece of reusable code

82
03:37.360 --> 03:41.040
that you can easily share. It doesn't even have to be authored by you the same

83
03:41.040 --> 03:42.080
way an Ansible role

84
03:42.080 --> 03:45.470
doesn't have to be authored by you. It can be authored by a teammate or perhaps

85
03:45.470 --> 03:46.400
even a community

86
03:46.400 --> 03:50.260
member that you don't even know personally. But ultimately, this role, or in

87
03:50.260 --> 03:51.360
the case of Python,

88
03:51.360 --> 03:56.660
this function can easily be imported into the logic of your code or in the term

89
03:56.660 --> 03:57.520
of Ansible

90
03:57.520 --> 04:00.790
into the logic of your Ansible playbook. Once again, it's all about making
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

90
03:57.520 --> 04:00.790
into the logic of your Ansible playbook. Once again, it's all about making

91
04:00.790 --> 04:02.000
things easier,

92
04:02.000 --> 04:06.200
more reusable and much more portable. Now, as we're going to learn, you can

93
04:06.200 --> 04:07.200
actually create

94
04:07.200 --> 04:11.520
your own Ansible role yourself. Now, in order to actually do this, what we're

95
04:11.520 --> 04:12.240
going to have to do

96
04:12.240 --> 04:16.690
is to follow a very particular directory structure. That means we're going to

97
04:16.690 --> 04:17.840
have very particular

98
04:17.840 --> 04:22.930
followers for very particular use cases, holding very particular playbooks and

99
04:22.930 --> 04:24.080
files. We will talk

100
04:24.080 --> 04:28.310
about that very, very shortly, but understand we absolutely do not have to

101
04:28.310 --> 04:29.200
create their own

102
04:29.200 --> 04:33.480
role ourselves. In fact, very often, people never really write their own roles.
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

102
04:29.200 --> 04:33.480
role ourselves. In fact, very often, people never really write their own roles.

103
04:33.480 --> 04:34.000
Very often,

104
04:34.000 --> 04:38.330
they just use the roles created by much more experienced users in the Ansible

105
04:38.330 --> 04:39.280
ecosystem.

106
04:39.280 --> 04:43.750
And one of the best places to get these type of roles is from a marketplace

107
04:43.750 --> 04:45.120
known as Ansible

108
04:45.120 --> 04:49.200
Galaxy. This too is something that we're going to be checking out within this

109
04:49.200 --> 04:50.240
particular scale.

110
04:50.240 --> 04:53.520
But before we get to Ansible Galaxy, the very first thing that I want to talk

111
04:53.520 --> 04:54.000
to you about

112
04:54.000 --> 04:58.730
is how we can go about creating our own customized and personal roles. But like

113
04:58.730 --> 04:59.440
you say, in order to

114
04:59.440 --> 05:03.130
do that, the very first thing that we have to understand is that very specific
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

114
04:59.440 --> 05:03.130
do that, the very first thing that we have to understand is that very specific

115
05:03.130 --> 05:03.840
Ansible directory

116
05:03.840 --> 05:07.430
structure and well that's what we're going to be talking about in the very next

117
05:07.430 --> 05:08.080
video.
