WEBVTT

1
00:00.000 --> 00:03.000
Okay friends, so let's walk through the solution then.

2
00:03.000 --> 00:05.720
So what I will do here is make sure I'm in my home directory.

3
00:05.720 --> 00:08.440
What I'm going to do is I'm going to create a directory simply called rows

4
00:08.440 --> 00:11.840
because as we recall in my Ansible CSG file,

5
00:11.840 --> 00:14.800
I actually have my rows here as part of my path.

6
00:14.800 --> 00:17.600
Okay, this is going to be a place where Ansible looks for these rows.

7
00:17.600 --> 00:20.480
So if I go into the rows directory right here,

8
00:20.480 --> 00:23.200
in order to generate the directory skeleton,

9
00:23.200 --> 00:26.120
I will say Ansible Galaxy, roll a net,

10
00:26.120 --> 00:27.560
and then I'll give the name of my row.

11
00:27.560 --> 00:29.160
So it's going to be called a welcome row.

12
00:29.160 --> 00:31.960
So if I hit enter, now the row has been created,
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

12
00:29.160 --> 00:31.960
So if I hit enter, now the row has been created,

13
00:31.960 --> 00:33.200
we can see it's right here.

14
00:33.200 --> 00:36.120
If I go into this directory structure and I just do a tree,

15
00:36.120 --> 00:38.840
we see we have all of our necessary files.

16
00:38.840 --> 00:40.400
Now the row is really quite simple.

17
00:40.400 --> 00:42.640
We're going to just render a simple template

18
00:42.640 --> 00:46.000
and then a reference that template within a task.

19
00:46.000 --> 00:48.560
So like I say here, we have this templates directory.

20
00:48.560 --> 00:51.640
This is a good place because this is where we can use our actual template.

21
00:51.640 --> 00:53.400
Let's create a little template, let's just call this,

22
00:53.400 --> 00:56.200
or let's just say welcome.j2.

23
00:56.200 --> 00:57.600
So that's going to insert mode.

24
00:57.600 --> 00:59.760
And all I'm going to have to say here is hello,

25
00:59.760 --> 01:04.480
my name is and then specify the name of the device within the Ansible inventory
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

25
00:59.760 --> 01:04.480
my name is and then specify the name of the device within the Ansible inventory

26
01:04.480 --> 01:04.480
.

27
01:04.480 --> 01:07.200
So I can use my double curly braces and then say,

28
01:07.200 --> 01:09.320
inventory_hostname.

29
01:09.320 --> 01:12.880
And then I'll just say welcome to RHC.

30
01:12.880 --> 01:15.200
So if I just write this out and quit,

31
01:15.200 --> 01:20.250
if I now go back and I now go into my tasks folder here to actually invoke a

32
01:20.250 --> 01:20.560
task,

33
01:20.560 --> 01:23.440
we have this main.yml file, let's go in and modify this,

34
01:23.440 --> 01:24.480
go into insert mode.

35
01:24.480 --> 01:27.200
And all I will do here is give this little task a name.

36
01:27.200 --> 01:30.160
I'll just say render a welcome message.
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

36
01:27.200 --> 01:30.160
I'll just say render a welcome message.

37
01:30.160 --> 01:33.200
So I will use the Ansible built-in template module right here.

38
01:33.200 --> 01:35.920
Now recall, if we don't remember how to actually use this, what can we do?

39
01:35.920 --> 01:38.640
We can say Ansible.dulk, Ansible built-in template.

40
01:38.640 --> 01:40.960
And to insert, we access to this documentation,

41
01:40.960 --> 01:44.160
we can see all the ways we can use this if we scroll all the way down,

42
01:44.160 --> 01:45.920
we come to some examples right here,

43
01:45.920 --> 01:48.080
so we can actually just copy this if we so wish,

44
01:48.080 --> 01:49.120
or just copy here.

45
01:49.120 --> 01:52.160
And let's just paste this in here actually, keep thinking this in simple.

46
01:52.160 --> 01:55.520
So I've already created the name and referenced the actual modules,

47
01:55.520 --> 01:57.040
let's delete these parts right here.

48
01:57.040 --> 01:59.040
And now I have all of my available parameters.

49
01:59.040 --> 02:02.240
Now what I want to do here is I want to specify the actual source.
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

49
01:59.040 --> 02:02.240
Now what I want to do here is I want to specify the actual source.

50
02:02.240 --> 02:06.960
Now by default Ansible, we'll look for the file within the template directory.

51
02:06.960 --> 02:08.960
So I'll just specify the name of the actual template,

52
02:08.960 --> 02:10.960
which is going to be called a welcome.j2.

53
02:10.960 --> 02:12.640
Now in the case of the owner, the group in the mode,

54
02:12.640 --> 02:14.160
we're not actually concerned about that right now,

55
02:14.160 --> 02:15.440
so we'll leave the defaults.

56
02:15.440 --> 02:19.220
And recall, where about do we actually have to write this to on our target

57
02:19.220 --> 02:19.920
devices?

58
02:19.920 --> 02:22.640
Well, I'm going to target the temp directory,

59
02:22.640 --> 02:25.200
and the filter be called welcome.txt.

60
02:25.200 --> 02:28.080
So with that now done, we have written our template,

61
02:28.080 --> 02:31.740
we have created our task, we want to tie this together with then an actual
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

61
02:28.080 --> 02:31.740
we have created our task, we want to tie this together with then an actual

62
02:31.740 --> 02:32.240
playbook.

63
02:32.240 --> 02:34.640
So let me go back to my main directory right here,

64
02:34.640 --> 02:39.280
I'll just now recall this welcome play dot yml, going to insert mode,

65
02:39.280 --> 02:41.200
have our three hyphens at the very top.

66
02:41.200 --> 02:43.600
I'll just say using my welcome role.

67
02:43.600 --> 02:45.280
Now who the host I'm going to target,

68
02:45.280 --> 02:47.040
in this case here, I'll target the all group.

69
02:47.040 --> 02:49.600
Once again, I'll set gather facts to be false.

70
02:49.600 --> 02:52.640
And now all I have to do is to specify the roles I want to use.

71
02:52.640 --> 02:56.480
I'll use the keyword roles and then a list object to determine which roles I

72
02:56.480 --> 02:57.440
want to include.

73
02:57.440 --> 02:59.920
Now in this case here, it's only going to be a one role,

74
02:59.920 --> 03:02.320
which is in fact simply called welcome role.
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

74
02:59.920 --> 03:02.320
which is in fact simply called welcome role.

75
03:02.320 --> 03:04.320
So if I just save this, and if I just say,

76
03:04.320 --> 03:07.200
"answerableplaybook" will come play dot yml, and to enter,

77
03:07.200 --> 03:10.480
now we're going to use the welcome role, and it seems to be actually have made

78
03:10.480 --> 03:11.200
a change.

79
03:11.200 --> 03:14.800
Now I can log into all devices, but in order to just check things really

80
03:14.800 --> 03:15.120
quickly,

81
03:15.120 --> 03:18.240
what I can do is also to say, "answerable all" dash a,

82
03:18.240 --> 03:20.640
and then I can just attempt to cat that particular fair,

83
03:20.640 --> 03:24.000
which is forward slash tmp forward slash welcome dot txt.

84
03:24.000 --> 03:26.880
If I enter, we log in to our devices.

85
03:26.880 --> 03:30.080
And as we can see here, we can see the content here as device number two,
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

85
03:26.880 --> 03:30.080
And as we can see here, we can see the content here as device number two,

86
03:30.080 --> 03:34.080
it's been rendered as hello, my name is device two, welcome to RHCE.

87
03:34.080 --> 03:38.160
And then we have device number one, hello, my name is device one, welcome to R

88
03:38.160 --> 03:38.880
HCE.

89
03:38.880 --> 03:42.600
So we did correctly render the templates and populate the value with the

90
03:42.600 --> 03:43.760
inventory name

91
03:43.760 --> 03:45.920
of the device itself with an answerable.
