Simplest Puppet Install Pattern

Version 9 (Nan Liu, 10/31/2011 09:03 am)

1 4 James Turnbull
# Getting Started with a Simple Puppet Pattern
2 1
3 1
Using Puppet is largely about developing the Puppet manifests,
4 1
which describe the configuration of your system.
5 1
6 7 James Turnbull
Once you have Puppet installed (see [Installation Guide](http://docs.puppetlabs.com/guides/installation.html)) on at
7 1
least one server (the Puppetmaster), and at least one client,
8 1
you're ready to set up a minimal configuration and get started
9 1
using Puppet.
10 1
11 6 Matt Griffith
If you want to test your Puppet manifests without installing a client and server you can run:
12 6 Matt Griffith
13 6 Matt Griffith
    puppet apply /etc/puppet/manifests/site.pp
14 6 Matt Griffith
15 1
# A Simple Manifest: Managing Ownership of a File
16 1
17 1
For our first manifest, we'll manage a single element (in this
18 1
case, a file) on all of our hosts.
19 1
20 1
## Step one: Create /etc/puppet/manifests/classes/sudo.pp
21 1
22 1
First, we'll create a class, which we'll call sudo, in the sudo.pp
23 1
manifest. We'll use this appropriately-named manifest for all
24 1
configuration information related to sudo, so next time we'll be
25 1
able to find the sudo stuff quickly. We'll start simple, and just
26 1
manage the sudoers file for now:
27 1
28 9 Nan Liu
    # /etc/puppet/modules/sudo/manifests/sudo.pp
29 1
    
30 1
    class sudo {
31 1
        file { "/etc/sudoers":
32 1
            owner => "root",
33 1
            group => "root",
34 1
            mode  => 440,
35 1
        }
36 1
    }
37 1
38 1
So now we have a class which will ensure that the owner, group, and
39 1
mode of the /etc/sudoers file will be set consistently across all
40 1
systems that belong to that class (but we haven't chosen which
41 1
computers belong in that class, yet).
42 1
43 1
## Step two: Create /etc/puppet/manifests/site.pp
44 1
45 1
Now we'll create the site.pp manifest which is the master manifest.
46 1
Puppet will search for a manifest by this name by default. Here's
47 1
our file:
48 1
49 1
    # /etc/puppet/manifests/site.pp
50 1
    
51 1
    node default {
52 1
        include sudo
53 1
    }
54 1
55 9 Nan Liu
After we create a default node definition, the default node definition will be applied
56 1
to any node that doesn't fall into any other node definition's
57 1
scope. In this case, since we have no other node definitions, all
58 1
nodes will follow this node definition and so any node will include
59 1
our sudo class.
60 1
61 1
## Step three: Start the Puppetmaster
62 1
63 1
Now that we have a basic manifest configuration laid out, we can
64 1
start the Puppetmaster daemon. We'll start the server with the
65 1
--mkusers option, so it creates the puppet user and group:
66 1
67 8 James Turnbull
    master % sudo puppet master --mkusers
68 1
69 1
This will background the daemon and send all of its logs to the
70 1
syslog facility. If you would prefer, you can add --verbose and the
71 1
daemon will stay in the foreground and its messages will go to the
72 1
terminal.
73 1
74 1
On Ubuntu and other Debian based distributions, starting the
75 1
Puppetmaster daemon works like this:
76 1
77 1
    master % sudo /etc/init.d/puppetmaster restart
78 1
79 1
## Step four: Run a client
80 1
81 1
It's usually best to start with your first client being
82 1
Puppetmaster server itself. However, since the Puppetmaster will be
83 1
talking to itself, that client will already have a certificate, so
84 1
no signing will be necessary to establish trust between the
85 1
Puppetmaster server and itself. In this example, we'll configure a
86 1
client that isn't the Puppetmaster server so we can demonstrate how
87 1
to establish cryptographic trust between the Puppetmaster server
88 1
and its new clients:
89 1
90 1
First, start puppetd on the client in verbose mode:
91 1
92 8 James Turnbull
    client% sudo puppet agent --verbose
93 1
94 1
You should see a message about not receiving a certificate, and on
95 1
the server you should get a message about a request waiting for
96 1
you. On the server, we'll list the certificates waiting for
97 1
signatures:
98 1
99 8 James Turnbull
    master% sudo puppet cert --list
100 1
101 1
You should see our client's name listed, so we can give the
102 1
Puppetmaster the command to sign its certificate (thus creating a
103 1
trust relationship that client):
104 1
105 8 James Turnbull
    master% sudo puppet cert --sign <client>
106 1
107 1
Within two minutes (the default value for --waitforcert), the
108 1
client should connect again and receive its signed certificate.
109 1
Once the signed cert is in place, the client should ask for its
110 1
configuration; the server will compile it (and log that it has done
111 1
so) and pass the compiled configuration to the client.
112 1
113 1
Then, if the sudoers file had incorrect permissions, we should see
114 1
one or more messages indicating the corrections; but if everything
115 1
about the sudoers file is already correct, you'll just see messages
116 1
about starting and ending the configuration run.
117 1
118 1
If you restart puppetd without the --verbose option, it will
119 1
background itself and run periodically thereafter, checking with
120 1
the Puppetmaster server to see if there the manifests have
121 1
changed.
122 1
123 1
## Caveat
124 1
125 1
This is half of the infrastructure for a working Puppet
126 1
installation. The other half of a hygienic and efficient
127 1
installation revolves around version-controlling the Puppet
128 1
manifests and the files Puppet will be managing. It also provides a
129 1
minimalist structure around which to build other Puppet classes.
130 1
131 1
## Where to next
132 1
133 5 James Turnbull
Have a look at the [[Advanced Puppet Pattern]] to see how we can
134 1
build on this basic recipe.