Now really to learn Puppet, we have to create code ourselves. So we're
going to take a look at this now. We can move into our Ansible directory,
and we can create a very simple message.pp file.
Now these are Ruby‑based files, so we could also,
if we have our modeline enabled,
we could add in some configuration to allow it to be
highlighted and work nicely with Vim.
We're using our notify resource, the name we're giving as Hello World,
and we're printing the Hello World message as well.
We can check our coding is correct using puppet parser and validate.
We can also run a smoke test where we don't actually do anything, so the
‑‑noop, so it can give us an idea if it's able to run the file. And then, of
course, we can apply our file. Notice we don't need the ‑e because we are
applying a manifest now. Now, of course,
that's really simple, but another really useful
mechanism is to take an existing resource,
maybe our existing user account, and store that as a
resource file, so our user.pp, our manifest.
We can go in then and edit that manifest and create a user from that.
Taking it a little bit further,
we can look at something a little bit more complex.
Let's say we want to ensure a configuration on our SSH server
where the root account is not allowed to log in.
We again can say our vim modeline.
We can define our service for the sshd.
We can make sure that the service is running, is enabled, and that's just
to ensure then that we have a record for your service.
The reason being is because we want to modify that service,
and we're going to need to restart it.
So we're using the file_line module.
This comes with our standard library. We're specifying the path,
so the sshd configuration. We want to ensure that a line is present,
not the file is present, but the line is present.
The line we're looking for is PermitRootLogin and no. We can search for
existing lines, for those lines that begin with PermitRootLogin.
So if it's already there, we can check that it's there, and we can also
go through and adjust it if it's set for something other than no. The
notify is then going to restart our service.
We've changed the configuration, the service is going to need to be restarted.
So we're going to be taking a look at these individually, and we're going
to be doing this at the command line, and as always, I really do encourage you to join us for the demonstrations.