Getting Started with Puppet
Puppet is a tool for configuration management, the puppet web page has this to say:
"Puppet lets you centrally manage every important aspect of your system using a cross-platform specification language that manages all the separate elements normally aggregated in different files, like users, cron jobs, and hosts, along with obviously discrete elements like packages, services, and files. Puppet’s simple declarative specification language provides powerful classing abilities for drawing out the similarities between hosts while allowing them to be as specific as necessary, and it handles dependency and prerequisite relationships between objects clearly and explicitly. Puppet is written entirely in “Ruby”(http://www.ruby-lang.org/)."
Configuration management by nature is a very complex task and while Puppet is simple once you know it the initial learning curve is can be very steep. As is often the case the temptation exist to just jump into the deep end and reference documentation only when needed. I'd strongly discourage this approach in the case of Puppet as only through systematic small steps working up to a more complex example will you understand the complete Puppet system.
It is often the case that a new user joins the irc channel and ask questions regarding a complex problem but without the background knowledge of doing simple things first with Puppet they do not understand the answers completely. This is frustrating for everyone involved.
I've written this guide for newcomers, it will guide you from starting with a blank system to a complete server and 1 or more clients that will have a centrally managed /etc/hosts file.
Managing just /etc/hosts sounds like a trivial thing to begin with, why do I not show you how to install Apache and some 3rd party application? The reason is simple we need a easily understandable and common resource that we all have and need and it should be sufficiently complex to show and teach a lot about puppet.
There are many approaches to dealing with /etc/hosts here are a few:
Copy the same /etc/hosts file to all your machines, making sure that when you add a new host you edit the central file and then copy it out
- Create per host specific files, allowing for customizations where needed but with the ability to fall back to the one-size-fits all file
Create just the entries you need on each host, using a template to generate /etc/hosts dynamically on a per hosts basis
Use a more specific method that is customized to managing /etc/hosts files on many different operating systems, perhaps leaving what is there by default alone and simply adding new hosts entries, allowing us to just put specific entries on the machine but perhaps not alter the ones that is there now.
Have machines 'register' themselves into /etc/hosts files of all other servers, have each server dynamically generate entries for all other machines.
So you can see /etc/hosts is potentially a pretty complex beast, luckily puppet can help you achieve each one of these goals some are simple some are more complex, but this guide will deal with each method.
The guide will start simple and progressively build up to the final goal, I really strongly urge you to work through this guide top to bottom even if you do not wish to manage /etc/hosts in this manner, the example was chosen because its both simple and complex enough to demonstrate a wide range of use cases for Puppet. Once you worked through all sections of this guide and understand them you will be able to successfully use the Puppet documentation and other guides to build your environment.
Requirements
There are things you are going to need to complete this guide:
- You should have 2 machines, one to act as a master and one as a client, you could do it with one but this will complicate things and in some cases hide certain complexities of dealing with remote clients. More importantly this guide is written with 2 machines and I'd say to complete the more complex examples you must have at least 2 machines. You can use virtual machines or real ones, it does not matter.
- You should know Linux or Unix already and you should be comfortable on the command line. Puppet cannot help you manage Unix machines if you do not already understand them. Once a large amount of Puppet manifests - or recipes - have been written by a knowledgeable then less knowledgeable ones can use them. But the audience for this guide is people who will write Puppet manifests.
- This guide is based on CentOS 5.2 servers, if you know Linux well enough this should not present a hurdle and I do reference Howtos for other distributions that should help you with the initial package installation. Ideally these would be new cleanly installed servers so that you can follow the guide from start.
These are things that may help you:
The Puppet Language Tutorial, Function Reference and Type Reference will be referenced a lot, bookmark them.
People often complain that the documentation are more Howtos and Receipes than professional guides, this might be the case on the Wiki but there is an excellent book called Pulling Strings With Puppet written by an very active member of the Puppet community called James Turnbull, it is an excellent resource and worth buying.
The Puppet IRC channel called #puppet hosted on freenode remember though this guide exists to help you slowly into the world of Puppet, if you seek help with a section in it please make sure you've covered earlier sections first.
The Puppet Users mailing list.
So if you're comfortable and ready to get started please head over to Part 1 to set up your Puppet Master.
Acknowledgments |
|
Jonathan A. Booth |
For helping with a review and making suggestions to the early versions of this document |
Changelog |
|
30/08/2008 |
Add Part 6 |
29/08/2008 |
Add an example using an if statement to the template in part 5 |
28/08/2008 |
Add Part 5 |
08/08/2008 |
Some cleanups and clarifications, add an acknowledgments segment |
08/08/2008 |
Add Part 4 |
07/08/2008 |
Initial release of Parts 1 to 3 |
