Thursday, October 6, 2011

Automatically Updating Your Puppet Masters’ Modules

One common problem with managing a puppet infrastructure is updating the modules on the Puppet Masters. If you're managing your Puppet modules in Version Control such as subversion or git (you ARE doing this, right?), you can have the Version Control System tell your Puppet Masters to update their checkout of whatever enviornment you’re currently checking code in to.

The mcmasterupdate module will install a MCollective agent called puppetupdate on whatever nodes you declare the mcmasterupdate class on. The mcmasterupdate module also contains an example SVN hook. Let's take a look at how this all works.

Requirements:

The following modules will be required:

  • mcollective
  • mcmasterupdate

You can download the mcmasterupdate and mcollective modules from the Puppet Labs github account.
http://www.github.com/puppetlabs/puppetlabs-mcmasterupdate
http://www.github.com/puppetlabs/puppetlabs-mcollective

Configuring the agent

The agent is managed from the mcmasterupdate class. Only declare this class on your Puppet masters. You'll also need the mcollective class to be declared. Here's an example on your Puppet masters.

class { 'mcollective':
  server          => false,
  client          => true,
  version         => '1.2.0',
  stomp_port      => 6163,
  stomp_server    => 'your.stomp.server',
  manage_packages => true,
  manage_plugins  => true,
}

class { 'mcmasterupdate': }


Configuring the hook

In the ext directory of the mcmasterupdate module, there is a post-commit.svn file for subversion. The only configuration necessary is to create the ENVIRONMENTS hash at the top of the file. The keys of the hash will be the names of your environments as configured in the puppet.conf file on your masters. The value for each key will be the regular expression used to match the files being committed to the appropriate environment. For this example, let's say you three environments, development, testing, and production. Your hash will look something like this:

ENVIRONMENTS = {
  'development' => /puppet\/trunk/,
  'testing'     => /puppet\/branch\/testing/,
  'production'  => /puppet\/tags/,
}

Put this file in the hooks directory of your subversion repository and name it 'post-commit'.

Now whenever you commit new Puppet code, the post-commit script will update the
checkouts on all the Puppet Masters for each environment you checked code in to.

0 comments: