So friends, and this particular video, what I want to do to talk to you about
some syntax issues that you may have with Ansible, because
quite honestly, this is a bit of a problem, YAML well, so it is very, very
human readable, it is nice to look at, but it can be very
per-negative with respect to syntax, that is because it is sensitive to white
space, and quite honestly, it happens to us all
misalignments within the document is going to happen, especially when you're
creating multiple different plays
with multiple different tasks, that type of thing. So let me just highlight WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
with multiple different tasks, that type of thing. So let me just highlight
some small issues that you can check, just as a way to help reduce the
frequency
of these errors. So what I will do here is, if I go and look at my Playbook
here, I've got Playbook 4, I believe. Yep, so all I
will do here is I will copy this one, play 4, and let me just create play5.yml.
So if I go inside here, now take for example, this
Playbook here, we've got two simple tasks, basically run a command, capture the
output, and then print that output. Now, what you
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
might do, in fact, I've very often done, is do something like this, okay? Knock
this in two spaces. When I look at this, it doesn't
always look like there's anything wrong. In fact, if you happen to look at a Y
AML format, and let me just grab this right here, and just
copy here. If you search for YAML syntax, check it here and go to this
particular page right here, and I paste this in. If I
click go, it tells me this is valid YAML. Now when I go to run this Playbook,
we're going to have an issue. So let's
save this. Let's run the Playbook. So as we can see here, we're getting our
error very crucially. We want to be reading the contents WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
error very crucially. We want to be reading the contents
of that message. It says here we have a failure, and it says the message is
that we have unsupported parameters for the
Ansible command, okay? Now again, this is why it's very important to really,
really read the actual output here. It does tell
us the module register, and again, the ugly line wrapping is a little bit
annoying, but nevertheless, that's what it's
saying here. This one is the problem. So by just looking at the output here, we
can see the module register is the issue at
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
hands. Now if we go back into our playbook, we need to understand the
relationship we're trying to establish here. By virtue of
having this parameter indented within the command parameter, we are effectively
saying that the register keyword belongs to
this particular module. Now is that actually true? Well, if you happen to go to
the documentation and you look through the
docs for Ansible built-in command, in fact, what I could do is just direct from
the command line, which is a very good way to
handle this problem. And I just say Ansible built-in command and to answer. Now
you're going to notice here in the actual WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
you're going to notice here in the actual
options, if I scroll on down all the way to R, notice we do not have a register
parameter. That is actually a separate
command altogether. It doesn't actually belong to the command module itself. So
both this playbook does contain valid
yaml syntax. It is actually erroneous on the basis of the Ansible configuration
itself. So as we know, this clearly doesn't
belong to the Ansible command utility. What we want to do is you want to out
dent it. So it's at the same level of indentation
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
as the command module. And this is going to make much more sense. So if I
happen to just save this right here, and I run
the playbook, hit enter, as we can see here, the playbook now successfully
executes. Now one thing I would recommend you do is
when you happen to be creating these playbooks is that you can use these online
tools such as yaml, lint, they can be very,
very handy. However, in the case of the examination, these online tools are not
going to be available to you. So whilst it's
good, as you learn and get familiar with building these playbooks and your
preparation to become more comfortable,
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
essentially, we would like to look at some tools we can actually use for real
to help us out. Now, just to be clear here, when
we happen to run an Ansible playbook, by default, Ansible is going to
automatically check the syntax. Let me show you what I
mean. So if I go back into my playbook right here, so what I will do here is I
will maybe change the indentation. Let's move
this in one space. Okay, so it's a little bit out same again here and again
here, because we don't have the consistent indentation
tasks here has a list out dented at this level, which is four spaces in. And
the next key is actually in dented five spaces. When I WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
the next key is actually in dented five spaces. When I
go to run the playbook, Ansible by default, like I say, is going to check the
syntax for me, it says here, the offending line
appears to be here. It tells us this is where the problem is at this portion
right here, the print the output stage. So I can
check that straight away. However, if you want to be able to just check your
syntax without having to run the playbook, so
basically, you want to make sure everything is in order before we even attempt
to push the changes, then we do actually have an
additional flag that we can specify known as syntax rather dash dash syntax WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
additional flag that we can specify known as syntax rather dash dash syntax
dash check. So let's see how this operates
them. So again, like you see, we have this slight indentation error here. If
though, when I go to run the playbook, I just
say dash dash syntax dash check and enter notice when there is an error, we get
the same type of output. But the difference
being is that when we happen to say, for example, fix the playbook so that
there are no problems at all. If I redone
the command and hit enter, it just gives me this nice little summary telling me
that this particular playbook is fine. Whereas if I WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
that this particular playbook is fine. Whereas if I
remove the syntax check when the playbook is going to operate and I enter, we
actually get the output, you see the difference. So a
good use case would be if you happen to have a whole bunch of playbooks. And
you just want to quickly check that the
syntax is OK, what you can do is say, Ansible playbook, and then say star,
which is a wildcard dot yaml. So pretty much
Ansible playbook for anything that ends in dot yaml. And then we can just say
dash dash syntax dash check. And all we're doing here
is seeing all of the playbooks that are correctly following the yaml syntax. WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
is seeing all of the playbooks that are correctly following the yaml syntax.
Now again, if we happen to make an error here,
let's go into let's maybe say play for this time. Again, let's maybe add a new
task, we're sitting on our test task, or just a debug
message here as a test. Because the indentation is actually a little bit out
here, if I just happened to run my syntax check against
all my playbooks, actually tells me where we have an error, it says the error
appears to be in the play for dot yaml of line 14 column
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
number four, it shows me exactly where the problem happens to be. So this can
be a very good way to quickly check all of your
playbooks have been correctly formatted in conjunction with the yaml standards.
But just understand because they are passing a syntax
check in yaml, that does not mean that the modules have been aligned correctly,
as we saw earlier before, like I say, with the
register module. So if you happen to be unsure whether or not a particular
keyword belongs to a particular module, then a quick
way to check that information would just be to use the answerable hyphen dot
command line utility in order to verify all of the WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
command line utility in order to verify all of the
correct parameters.