Now to really begin our understanding of Puppet, we're going to work
with manifests, beginning by creating a very simple manifest,
printing information, but more importantly,
seeing how we can use existing resources to create
templates for manifests. And here we are,
the glorious command line.
Let's begin by just taking a look at my standard user's home
directory and take a look inside the .vimrc file.
Now with this, I configured for a dark background, and I
have the the vim modeline enabled.
This is going to help us when editing our manifest files. We
can move into then our Puppet directory.
We should have created this earlier, and it will be a new and
empty directory, but we're going to change that, oh yes we are!
Let's go through and create a new manifest. Now, manifests then
have a .pp extension.
Now having opened up that file in our vim text editor,
we can go through and add the modeline extension so we work with the
correct syntax. It's going to be a commented line, so we're going to begin
with a hash. We're specifying that this is for vim. This is more
documentation, but then colon. As we then go through, we can set then our
file type to =ruby, so we get the correct color coding. And then we can
say auto indent, so we returned to the same indent level as we worked on
the previous line.
We can expand tabs and store tabs as two spaces.
The shift width, which is used by auto indent, should be set to 2 as well,
so we can configure this. And then that's everything that we need to
configure our correct workings for a manifest. Make sure we've got the
colon on the end and save the file. Going back in, we can see now that has
been read. As we go through, we can start adding then our proper Ruby code.
We can begin with our notify resource.
We want to just display a message. We can go through and open up
then the properties of the resource with our brace brackets and
specify a name for this resource.
Now the name doesn't really matter in this case because
this is kind of the name of the message,
not the message that is being displayed.
So we're just going to use 'Hello world.' After the name, we
have the properties, so we specify a colon.
We can tab in and we can see we've got our two spaces,
and we just need the one property,
our message. We separate the key and the value through the
big arrow key, and we can then have our "Welcome to puppet,"
or whatever message that we want.
Now, the spelling doesn't really matter, it's just a message, but we can
always tidy it up if you're as bad a typer as I am, and then when we're
ready, we can go through, move back to our left‑hand side, and then just
close off our brace brackets.
Now that's then our manifest file in its simplest format.
We can save the change. Now hopefully we haven't got any
errors, but we can run our puppet parser and validate to
check our code. Now, again, this is just a warning that we're getting from Ruby.
It's nothing to do with the validation. So everything is okay.
No output is good output. But we can take it one step further and run
then our puppet apply, but if we're cautious about applying it and we
want to see what would happen at runtime,
we can execute it with ‑‑noop. Now, probably we're going to get a
lot of Ruby messages coming back, so we can turn those off by
redirecting them through to dev/null.
And the big thing here is we would have, but we haven't. We
would have displayed the message, but we didn't.
So if we were truly making a configuration change,
if that change did need to be taken place,
we would see what would happen. If we're happy with this,
we can change then the no operation to a full operation, and we
can see then the message is being displayed.
Now,
of course this is akin to a 'Hello world' message, so I know
it's not going to be rocking your socks off,
but it's a start.
Let's go through now and create ourselves a new manifest.
We can add our modeline in automatically by reading the top line of our
message.pp, redirect that through to our user.pp.
The next thing,
we're still going to be working with templating, and we know that
if we use puppet resource and take a look at a user resource for
our current user, $USER, we're going to see the current settings
for that user. Again,
redirecting any error messages that is coming through from
Ruby. We can take our standard output and append the two
great events through to our user.pp.
Now with that done, if I try and edit the user manifest,
we can see it's all laid out very nicely, I can use this as a
template for managing a different user.
I can move down to my user name,
the name of the resource, and we can set, let's say Bill or
Fred or Joe or Josie, whatever you like.
We can set a full name.
So I can go through and change the comment through to 'fred bloggs.' I
don't really need a group ID, so we can remove that.
I don't really need the user ID, so I'm going to remove that.
And to be honest,
we can pick up the home from the defaults in any case, so I'll remove that.
But with this set now, we are ready to go.
Of course, I need to elevate my privileges to be able to create a user
account, but if I run then my puppet apply and then the user.pp, if the
user Fred is not there with the correct properties,
it's going to be adjusted. Again,
we're going to redirect our warnings through to dev/null,
hit the big Enter key, and we can see now that the Fred user has been created.
Now this gives you an idea of a simple manifest. Let's just step it up now, editing a file.