at⋅a⋅rax⋅is

Deploying Puppet to manage systems

Contents

Background

Around 2004, I developed a crude system to syncronize configuration among systems. I don’t remember what I called it.

Around 2003, we started using CFengine to manage systems in the Computer Science department, but found it cumbersome.

Around 2008, we switch to an early version of Puppet.

For the cannonical docs, see https://cs.stanford.edu/system-administration-guide/software/puppet

Below is an old copy of that document.

Modifying the Puppet Configuration

The puppet configuration files for CSD-CF are stored in a git repository (several, actually). In order to make changes you need to clone the primary repository, make your changes and commit them using git. The details of the process are outlined below. This may seem like a pain, but the intention is to prevent errors going directly to production, and possibly breaking hundreds of systems.

The term ‘branch’ refers to the state of your git repo, while the term ‘environment’ means a specific set of puppet configuration files. For the most part, they are the same name, with the exception of the ‘development’ environment, which is the git ‘master’ branch.

Setup your Repository

Setup your repository – you only need to do this once, unless you nuke your local repo and are starting over.

Setup your repo

git clone /afs/cs/dept/git/puppet.git
cd puppet
git config --add push.default tracking # Only push current branch, rather than all

Setup production branch, track main repo

git checkout -b production origin/production

Setup up your Development Environment

Branching is a way for you to make changes to the puppet configuration and test them before releasing to production. It’s best if you use your own branch to avoid interfering with others or merging somebody else’s half-done modifications. When you push your branch to the central repo, a script is automatically executed which sets up the puppet environments in vigilante:/etc/puppet/environments (assuming the computer you’re pushing from can ssh to vigilante). You can of course setup as many branches as you like. Don’t use any punctuation in your branch name – git doesn’t mind, but puppet does.

Setup your own development branch and make it the active one

git checkout -b devmiles

Push your remote branch and setup tracking

git push -u origin devmiles

check what branch you’re on; -a lists all (including remote).

git branch

Testing your Environment

Running git push in your branch will automatically setup a new puppet environment of the same name. You should test any changes before merging into production. The --noop argument to puppetd tells puppet to not actually make the changes, just show what would happen. If you run puppetd without noop, the node will be configured to use your environment permenantly (until it’s changed again by running puppetd with the --environment argument).

commit and push your changes

git commit; git push

test development branch on node foo without changing anything

ssh root@foo puppetd -tv --noop --environment devmiles

or, switch a node over to your environment

ssh root@foo puppetd -tv --environment devmiles

Put a node back in the production environment

ssh root@foo puppetd -tv --environment prodcution

Releasing to Production

When you`ve tested your changes (and you did test them, right?), and are ready to change the production puppet environment, you will merge your branch into the production branch:

commit and push your changes

git checkout production

merge your development branch into production

git merge devmiles

Push out to git repo (and from there, automatically, the puppet server)

git push

Caveats, Warnings and FAQs

The computer youre running git commands on must be able to ssh to vigilante to update the puppet master server. If for some reason the push failed to set up the puppet environments as you expected, you can run make release`, which runs the same command as the git post hook script.

Q: I was working on my branch, but somebody made changes to production – how do I get those? A: Merge the prodction branch into yours; make sure you’re in the right branch, then git merge production

=======

Older documentation

The puppet configuration files for CSD-CF are stored in a git repository (several, actually). In order to make changes you need to clone the primary repository, make your changes and commit them using git. The details of the process are outlined below.

The primary repository is located at /afs/cs/dept/git/puppet.git. Choose a workspace (say, ~/git) and run

git clone /afs/cs/dept/git/puppet.git

This will create a ‘puppet’ subdirectory containing a complete copy of the git repository and a working checkout of the files. In there, you can modify/remove/add files as you would any normal files – there is only one git command to run when you’re ready to commit any changes:

git commit -a

Now you have commited the changes to your local copy of the repo – git is distributed, so now you need to syncronize your repo with the master copy:

git push

Almost there. The puppet master daemon uses files in it’s own working git repo, vigilante:/etc/puppet. Now you need to have that repo ‘pull’ the changes you’ve committed and pushed. Manually this would involve running git pull from that directory, but to make things slightly easier (and enforce some things via shell script) there is a make target to do it for you:

make release

#============================================================================== Common file headers/footers

(is this relevant anymore? git doesn’t have substitution built in)

It’s generally a good idea that all files have the following comments at the top (or right after #! if executable):

# $Id$
# vi: shiftwidth=4 tabstop=4 smarttab expandtab formatoptions=croql

(insert lines for your favorite editor, if available, above)

#==============================================================================

File Hierarchy
--------------

All Puppet data files (modules, manifests, distributable files, etc) should be maintained in Subversion (or whatever we move to later). The following hierarchy describes the layout used in CSD-CF:

    /etc/puppet/
    |
    |-- contrib					Freely available modules for example use
    |
    |-- manifests				Think of this as the master directory.
    |   |-- classes				
    |   |   |-- device.pp		Classes based on Zenoss Devices
    |   |   |-- group.pp		Classes based on Zenoss Groups
    |   |   |-- location.pp 	Classes based on Zenoss Locations
    |   |   |-- priority.pp 	Classes based on Zenoss Priorities
    |   |   |-- state.pp		Classes based on Zenoss Production State
    |   |   `-- system.pp		Classes based on Zenoss Systems
    |   |
    |   |-- modules.pp			Imports things from modules directory below
    |   |-- nodes.pp			Nodes must be defined in this file by hand
    |   |-- site.pp				"Main" file. It all starts here.
    |   `-- templates.pp		Templates allow you to manage the content of 
    |                           template files, for example configuration files 
    |                           that cannot yet be managed as a Puppet type.
    |
    |-- modules					Directory for modules
    |   |
    |   `-- openafs				An example module
    |       |-- files			Files related to this module, usually for download
    |       |-- lib			    Extentions / plugins to puppet and / or facter go here
    |       `-- manifests		Puppet confs
    |           `-- init.pp		Puppet configuration file for this module
    |
    |
    |-- notes                   ?
    |-- services                ?
    `-- tools					Helper programs and local scripts


/manifests/: this directory contains files and subdirectories that determine
the manifest of individual systems but do not logically belong to any
particular module.  Generally, this directory is fairly thin and alternatives
such as the use of LDAP or other external node tools can make the directory
even thinner. This directory contains the following special files: 

	site.pp: first file that the Puppet Master parses when determining a
	server's catalog. It imports all the underlying subdirectories and the 
	other special files in this directory. It also defines any global 
	defaults, such as package managers. 

	templates.pp: defines all template classes. 

	nodes.pp: defines all the nodes if not using an external node tool.

/modules/{modulename}/: houses puppet modules in subdirectories with names
matching that of the module name. This area defines the general building blocks
of a server and contains modules such as for openssh, which will generally
define classes openssh::client and openssh::server to setup the client and
server respectively. The individual module directories contains subdirectories
for manifests, distributable files, and templates. 

/modules/user/: A special module that contains manifests for users. This module
contains a special subclass called user::virtual which declares all the users
that might be on a given system in a virtual way. The other subclasses in the
user module are classes for logical groupings, such as user::unixadmins, which
will realize the individual users to be included in that group. 

/services/: This is an additional modules area that is specified in the module
path for the puppetmaster. However, instead of generic modules for individual
services and bits of a server, this module area is used to model servers
specific to enterprise level infrastructure services (core infrastructure
services that your IT department provides, such as www, enterprise directory,
file server, etc). Generally, these classes will include the modules out of
/modules/ needed as part of the catalog (such as openssh::server, postfix,
user::unixadmins, etc). The files section for these modules is used to
distribute configuration files specific to the enterprise infrastructure
service such as openldap schema files if the module were for the enterprise
directory. To avoid namespace collision with the general modules, it is
recommended that these modules/classes are prefixed with s_ (e.g. s_ldap for
the enterprise directory server module)

/clients/: similar to the /services/ module area, this area is used for modules
related to modeling servers for external clients (departments outside your IT
department).  To avoid namespace collision, it is recommended that these
modules/classes are prefixed with c_.  

/notes/: this directory contains notes
for reference by local administrators.

/plugins/: contains custom types programmed in Ruby.

/tools/: contains scripts useful to the maintenance of Puppet.

# References

Old Good starting points:

[^1]:  http://insight.fab-it.dk/2008/08/23/how-to-write-a-puppet-module/
[^2]: http://reductivelabs.com/trac/puppet/wiki/DocumentationStart
[^3]: http://reductivelabs.com/trac/puppet/wiki/InfrastructureDesignGuidelines
[^4]: Manage Macs with Puppet (http://code.google.com/p/puppet-mw08/)downloads/list

From Puppet Best Practices 2.0
http://reductivelabs.com/trac/puppet/wiki/PuppetBestPractice#file-hierarchy



Somewhere the original Subversion repo may exist `/afs/cs.stanford.edu/dept/svn/puppet`