[Autogenerated] You may already be aware of YAML data.
It's used in different scenarios if you're used to working with salt
stack or if you're used to working with answerable,
they take YAML data for their state definition files.
But also YAML is used in such files as the net plan file on our
latest Ubuntu systems for the network configuration.
So it is quite common but its a little bit different perhaps from other formats,
we can begin by simple key value pairs and these are
written really easily its key,
the name of the key followed by a colon followed by the value that we want.
So space and value.
So this is quite normal.
However,
we can also have things call dictionary which are a
collection of key value pairs.
But so we know that we belong to the dictionary,
we have to indent with spaces at the same level.
So often this is two spaces in the white space is significant.
We can also have lists again,
these are indented below the dictionary that they are
part of and they start with a hyphen.
Now you're never going to understand this until you start seeing it.
So don't worry too much.
This just lays out some of the format for you.
But if we take a look at a sample YAML file,
we can then go through and have a users dictionary.
It doesn't have a value after it's the key because
we've got a colon but there's no value.
So a dictionary just has multiple key value pairs.
This one though starts with a dash or a hyphen.
So when we look at this, this is a list item,
the users dictionary will contain a list of users.
This user is called Bob.
It's got a value.
Now we're looking at key pairs and the key here is plus W D,
it's indented below the user.
So we're not lining up with the hyphen the dash, we're lining up two spaces in.
So with the U of user, the user ID, the group ID D and the comment,
the home directory and the default shell as we then continue,
we can add in another user.
So now our indent moves back, we begin with a list item.
So dash and now we have another user this time, it's called FRED.
And of course, we could continue with this.
Now to be able to convert our past W D file to this,
there's a little bit more work that is needed.
So we can use an arc file rather than putting everything at the command line.
Remember our arc files,
give us the ability to be able to save our argument through
to arc in our file for repeatability.
Here's just an extract of the file that is going to be created or
you can use the one that's part of our Git repo.
So within our begin block, we can set our field separator,
we can also print our dictionary.
So users colon followed bi our space,
we can close the begin block and we can open up our main block here.
We're going through a loop.
So we're looking at starting our field number I on one until
we've gone through all of the number of fields.
Now, we know there's seven fields.
So I could put just the number seven there.
But if we don't know how many fields, we can count the number of fields.
So we iterate through each field,
we increment our counter I which is going to be used as
our variable for our field number.
We then go into our four loop.
And here we're running a switch statement where we're reading
the case or the state of our variable I,
if it has a value one I E, we're on the first field,
we can then run our print F statement.
Print F allows our formatting.
We've got two leading spaces,
our dash and then our user and then we're printing a space holder for a string
and we're populating that with the dollar I and a new line.
That's the end of our case statement.
We can go to case two.
If the value of our field is two, we can say its our password field and break.
Now, of course,
it's going to continue through the case statement as we start
looking at the different case of the field.
So for each field, we can print out the correct item.
But again,
we got to make sure we've got the correct number of spaces
and its printing the way that we want.
Now, the best way to learn as always, you know,
I say this every single time is to get some practice,
we can use the git repository for our password to YAML file,
but we can also create a smaller version just to get it up and running.
So we get the idea of what's going on.
So come on,
let's move through to our command line and I expect to
see you at your command line two.