We're going to take a look at some of our file formats, starting with YAML.
No, not yelling at my laptop.
No, yet another markup language.
A lot of people think this, but it's not.
YAML ain't markup language, it's a data‑structure language similar to JSON,
but without all of the extra syntax elements.
When we look at a YAML file, it could start with ‑‑‑,
a doc Header, it's optional, but it should start with three dashes.
We can have a simple key‑value pair, so file: and then my.file.
We can create a list, so names:, but nothing follows that.
After that, we then have ‑ fred, ‑ bill being our List items.
List items start with a dash.
And then we can look at a dictionary.
Here we've got the key package.
Again, nothing follows it.
But when we look at a dictionary, it is a list of key‑value pairs.
So we have name, having the value of tree, and state, being installed.
Finally, we can have a doc footer.
Again, this is optional.
It's not really required.
However, it should be there if we want to keep it 100% correct.
So the doc Header, three dashes, the dock footer, three dots.
We're going to go through now and take a look at writing YAML files.
We'll see how we can create a YAML file,
configure VIM, so it works nicely for us with YAML files,
and look at linting our YAML file once we've created it.
So come on, let's write our first YAML file.
Now we're going to look at how we can create a vimrc
file to support our YAML syntax.
YAML is space sensitive,
and we need to make sure that we are using spaces and not tabs.
I'm working on my host machine.
It doesn't really matter if you're working on your host
machine or on your guest machine at the moment.
We'll probably configure both .vimrc files to be the same way.
But let's go through now and start editing my .vimrc file,
so it will support the syntax that I like for editing YAML files.
As we then go through and open up our .vimrc file,
we can see then that we've got our settings that we are using at the moment,
but this would be for every single file.
If we go through and put autocmd,
then we only run these commands when we match our condition.
And we're looking for a FileType being of yaml,
that can be .yaml files or .yml files.
We can overwrite anything we might get from the system, so setlocal.
And we can set then our auto indent.
Our expand tabs, so we save tabs and spaces,
and we're saving them as two spaces.
We're also setting the shift width, same as we did before for two spaces.
And we can set a couple of other items that are very useful.
Cuc, which then gives me my column highlighting,
and cul, that gives me my underlying highlighting,
and we'll see how they come into play.
If I go through now and create myself a YAML file,
so using the extension .yaml or .yml.
We can go through, and let's correctly put in our doc header.
Remember, a doc header is our three dashes.
So when we go into our INSERT mode, add our three dashes,
at least we're meeting certain standards now that we're
defining this as a YAML document.
A simple key‑value pair, name followed directly by a colon, and then the value.
We don't quote strings unless they contain special objects.
When we go through and take a look at a list,
we can have the key called items, which has then multiple values,
and each of these values then is entered with the dash in front of them,
followed by a space.
You can see the underline working for me,
so I can see which line that I'm working on,
and we can also see the vertical bar being very useful to make
sure that everything is lined up nicely.
We can now go through and take a look at a dictionary, so package and colon.
And we can then go through and put key‑value pairs,
such as the name of the package we want installed perhaps,
and the state, say, that we wanted installed or maybe even removed.
So this is really how we write YAML.
And don't forget, we can have then our document footer.
Now to I say,
I do like the idea of these highlighting so you can see which line
that I'm on with the horizontal bar or vertical bar.
That means that I can look to see that everything is lined up nicely.
As I go through then and save my file,
we're also going to make sure that we've written this
syntactically correct and tidily for YAML.
So we're going to go through and update our package cache,
so our normal Ubuntu and Debian way of managing our software.
And once we've updated the cache,
we're then going to do a sudo and apt install and yamllint.
We can go through and accept the recommendations.
It should install very quickly.
And then we can just go through and check that everything is correct within
our YAML file, just yamllint and the name of our file,
so just putting in then our my.yaml.
But coming back with nothing doesn't give you a great deal of confidence.
If we want to, we can add in the ‑v switch for verbose,
which will then go through and show me the version number, but
it's good if we're getting silent output. But there you go, we've written some YAML.