WEBVTT

1
00:00.000 --> 00:03.790
So friends, and this particular video, what I want to do to talk to you about

2
00:03.790 --> 00:07.680
some syntax issues that you may have with Ansible, because

3
00:07.680 --> 00:12.160
quite honestly, this is a bit of a problem, YAML well, so it is very, very

4
00:12.160 --> 00:15.940
human readable, it is nice to look at, but it can be very

5
00:15.940 --> 00:21.150
per-negative with respect to syntax, that is because it is sensitive to white

6
00:21.150 --> 00:23.780
space, and quite honestly, it happens to us all

7
00:23.780 --> 00:27.260
misalignments within the document is going to happen, especially when you're

8
00:27.260 --> 00:28.980
creating multiple different plays

9
00:28.980 --> 00:32.270
with multiple different tasks, that type of thing. So let me just highlight
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

9
00:28.980 --> 00:32.270
with multiple different tasks, that type of thing. So let me just highlight

10
00:32.270 --> 00:35.860
some small issues that you can check, just as a way to help reduce the

11
00:35.860 --> 00:36.360
frequency

12
00:36.360 --> 00:40.370
of these errors. So what I will do here is, if I go and look at my Playbook

13
00:40.370 --> 00:42.620
here, I've got Playbook 4, I believe. Yep, so all I

14
00:42.620 --> 00:47.630
will do here is I will copy this one, play 4, and let me just create play5.yml.

15
00:47.630 --> 00:50.360
So if I go inside here, now take for example, this

16
00:50.360 --> 00:54.270
Playbook here, we've got two simple tasks, basically run a command, capture the

17
00:54.270 --> 00:57.280
output, and then print that output. Now, what you

18
00:57.280 --> 01:01.700
might do, in fact, I've very often done, is do something like this, okay? Knock
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

18
00:57.280 --> 01:01.700
might do, in fact, I've very often done, is do something like this, okay? Knock

19
01:01.700 --> 01:04.960
this in two spaces. When I look at this, it doesn't

20
01:04.960 --> 01:08.730
always look like there's anything wrong. In fact, if you happen to look at a Y

21
01:08.730 --> 01:11.400
AML format, and let me just grab this right here, and just

22
01:11.400 --> 01:15.340
copy here. If you search for YAML syntax, check it here and go to this

23
01:15.340 --> 01:18.600
particular page right here, and I paste this in. If I

24
01:18.600 --> 01:22.160
click go, it tells me this is valid YAML. Now when I go to run this Playbook,

25
01:22.160 --> 01:24.160
we're going to have an issue. So let's

26
01:24.160 --> 01:27.420
save this. Let's run the Playbook. So as we can see here, we're getting our

27
01:27.420 --> 01:30.680
error very crucially. We want to be reading the contents
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

27
01:27.420 --> 01:30.680
error very crucially. We want to be reading the contents

28
01:30.680 --> 01:34.740
of that message. It says here we have a failure, and it says the message is

29
01:34.740 --> 01:38.120
that we have unsupported parameters for the

30
01:38.120 --> 01:42.030
Ansible command, okay? Now again, this is why it's very important to really,

31
01:42.030 --> 01:44.580
really read the actual output here. It does tell

32
01:44.580 --> 01:48.480
us the module register, and again, the ugly line wrapping is a little bit

33
01:48.480 --> 01:50.660
annoying, but nevertheless, that's what it's

34
01:50.660 --> 01:54.420
saying here. This one is the problem. So by just looking at the output here, we

35
01:54.420 --> 01:56.960
can see the module register is the issue at

36
01:56.960 --> 02:00.320
hands. Now if we go back into our playbook, we need to understand the
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

36
01:56.960 --> 02:00.320
hands. Now if we go back into our playbook, we need to understand the

37
02:00.320 --> 02:03.760
relationship we're trying to establish here. By virtue of

38
02:03.760 --> 02:09.610
having this parameter indented within the command parameter, we are effectively

39
02:09.610 --> 02:12.840
saying that the register keyword belongs to

40
02:12.840 --> 02:16.380
this particular module. Now is that actually true? Well, if you happen to go to

41
02:16.380 --> 02:18.040
the documentation and you look through the

42
02:18.040 --> 02:21.410
docs for Ansible built-in command, in fact, what I could do is just direct from

43
02:21.410 --> 02:23.100
the command line, which is a very good way to

44
02:23.100 --> 02:27.980
handle this problem. And I just say Ansible built-in command and to answer. Now

45
02:27.980 --> 02:30.180
you're going to notice here in the actual
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

45
02:27.980 --> 02:30.180
you're going to notice here in the actual

46
02:30.180 --> 02:35.300
options, if I scroll on down all the way to R, notice we do not have a register

47
02:35.300 --> 02:38.140
parameter. That is actually a separate

48
02:38.140 --> 02:42.920
command altogether. It doesn't actually belong to the command module itself. So

49
02:42.920 --> 02:45.160
both this playbook does contain valid

50
02:45.160 --> 02:49.720
yaml syntax. It is actually erroneous on the basis of the Ansible configuration

51
02:49.720 --> 02:51.760
itself. So as we know, this clearly doesn't

52
02:51.760 --> 02:55.340
belong to the Ansible command utility. What we want to do is you want to out

53
02:55.340 --> 02:58.960
dent it. So it's at the same level of indentation

54
02:58.960 --> 03:02.330
as the command module. And this is going to make much more sense. So if I
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

54
02:58.960 --> 03:02.330
as the command module. And this is going to make much more sense. So if I

55
03:02.330 --> 03:04.760
happen to just save this right here, and I run

56
03:04.760 --> 03:08.450
the playbook, hit enter, as we can see here, the playbook now successfully

57
03:08.450 --> 03:11.080
executes. Now one thing I would recommend you do is

58
03:11.080 --> 03:15.640
when you happen to be creating these playbooks is that you can use these online

59
03:15.640 --> 03:17.800
tools such as yaml, lint, they can be very,

60
03:17.800 --> 03:21.430
very handy. However, in the case of the examination, these online tools are not

61
03:21.430 --> 03:24.000
going to be available to you. So whilst it's

62
03:24.000 --> 03:27.320
good, as you learn and get familiar with building these playbooks and your

63
03:27.320 --> 03:29.320
preparation to become more comfortable,

64
03:29.320 --> 03:32.520
essentially, we would like to look at some tools we can actually use for real
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

64
03:29.320 --> 03:32.520
essentially, we would like to look at some tools we can actually use for real

65
03:32.520 --> 03:35.400
to help us out. Now, just to be clear here, when

66
03:35.400 --> 03:38.730
we happen to run an Ansible playbook, by default, Ansible is going to

67
03:38.730 --> 03:41.160
automatically check the syntax. Let me show you what I

68
03:41.160 --> 03:44.510
mean. So if I go back into my playbook right here, so what I will do here is I

69
03:44.510 --> 03:46.560
will maybe change the indentation. Let's move

70
03:46.560 --> 03:49.980
this in one space. Okay, so it's a little bit out same again here and again

71
03:49.980 --> 03:53.000
here, because we don't have the consistent indentation

72
03:53.000 --> 03:57.900
tasks here has a list out dented at this level, which is four spaces in. And

73
03:57.900 --> 04:01.320
the next key is actually in dented five spaces. When I
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

73
03:57.900 --> 04:01.320
the next key is actually in dented five spaces. When I

74
04:01.320 --> 04:04.570
go to run the playbook, Ansible by default, like I say, is going to check the

75
04:04.570 --> 04:07.480
syntax for me, it says here, the offending line

76
04:07.480 --> 04:11.450
appears to be here. It tells us this is where the problem is at this portion

77
04:11.450 --> 04:14.680
right here, the print the output stage. So I can

78
04:14.680 --> 04:19.020
check that straight away. However, if you want to be able to just check your

79
04:19.020 --> 04:22.240
syntax without having to run the playbook, so

80
04:22.240 --> 04:26.040
basically, you want to make sure everything is in order before we even attempt

81
04:26.040 --> 04:28.440
to push the changes, then we do actually have an

82
04:28.440 --> 04:33.580
additional flag that we can specify known as syntax rather dash dash syntax
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

82
04:28.440 --> 04:33.580
additional flag that we can specify known as syntax rather dash dash syntax

83
04:33.580 --> 04:35.840
dash check. So let's see how this operates

84
04:35.840 --> 04:39.890
them. So again, like you see, we have this slight indentation error here. If

85
04:39.890 --> 04:41.800
though, when I go to run the playbook, I just

86
04:41.800 --> 04:46.680
say dash dash syntax dash check and enter notice when there is an error, we get

87
04:46.680 --> 04:49.040
the same type of output. But the difference

88
04:49.040 --> 04:52.220
being is that when we happen to say, for example, fix the playbook so that

89
04:52.220 --> 04:55.160
there are no problems at all. If I redone

90
04:55.160 --> 04:58.750
the command and hit enter, it just gives me this nice little summary telling me

91
04:58.750 --> 05:02.040
that this particular playbook is fine. Whereas if I
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

91
04:58.750 --> 05:02.040
that this particular playbook is fine. Whereas if I

92
05:02.040 --> 05:06.210
remove the syntax check when the playbook is going to operate and I enter, we

93
05:06.210 --> 05:09.280
actually get the output, you see the difference. So a

94
05:09.280 --> 05:12.660
good use case would be if you happen to have a whole bunch of playbooks. And

95
05:12.660 --> 05:14.560
you just want to quickly check that the

96
05:14.560 --> 05:19.110
syntax is OK, what you can do is say, Ansible playbook, and then say star,

97
05:19.110 --> 05:21.760
which is a wildcard dot yaml. So pretty much

98
05:21.800 --> 05:26.000
Ansible playbook for anything that ends in dot yaml. And then we can just say

99
05:26.000 --> 05:29.600
dash dash syntax dash check. And all we're doing here

100
05:29.600 --> 05:33.130
is seeing all of the playbooks that are correctly following the yaml syntax.
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

100
05:29.600 --> 05:33.130
is seeing all of the playbooks that are correctly following the yaml syntax.

101
05:33.130 --> 05:35.320
Now again, if we happen to make an error here,

102
05:35.320 --> 05:39.270
let's go into let's maybe say play for this time. Again, let's maybe add a new

103
05:39.270 --> 05:42.080
task, we're sitting on our test task, or just a debug

104
05:42.080 --> 05:46.560
message here as a test. Because the indentation is actually a little bit out

105
05:46.560 --> 05:49.720
here, if I just happened to run my syntax check against

106
05:49.720 --> 05:53.570
all my playbooks, actually tells me where we have an error, it says the error

107
05:53.570 --> 05:58.080
appears to be in the play for dot yaml of line 14 column

108
05:58.080 --> 06:02.040
number four, it shows me exactly where the problem happens to be. So this can
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

108
05:58.080 --> 06:02.040
number four, it shows me exactly where the problem happens to be. So this can

109
06:02.040 --> 06:04.080
be a very good way to quickly check all of your

110
06:04.080 --> 06:08.060
playbooks have been correctly formatted in conjunction with the yaml standards.

111
06:08.060 --> 06:10.840
But just understand because they are passing a syntax

112
06:10.840 --> 06:14.760
check in yaml, that does not mean that the modules have been aligned correctly,

113
06:14.760 --> 06:17.080
as we saw earlier before, like I say, with the

114
06:17.080 --> 06:20.950
register module. So if you happen to be unsure whether or not a particular

115
06:20.950 --> 06:23.720
keyword belongs to a particular module, then a quick

116
06:23.720 --> 06:27.310
way to check that information would just be to use the answerable hyphen dot

117
06:27.310 --> 06:30.240
command line utility in order to verify all of the
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

117
06:27.310 --> 06:30.240
command line utility in order to verify all of the

118
06:30.240 --> 06:31.440
correct parameters.
