Server Variables in Puppet Templates

Puppet is an invaluable tool for managing a large number of Linux servers. By defining different classes for each service I deploy, I can easily define what runs on each server I control just by changing the site manifest.

A problem I ran into early when I was bringing services into Puppet was slightly different configurations on servers with different specs. For example, I run Tomcat on three servers but one is also running some other services. On this one server the JVM maximum heap size needs to be lower than on the others, but the rest of the Tomcat configuration is the same. To manage this without making a second class definition I used the template system in Puppet.

There are four steps to making this work. First you need to define a default for the variable. Next you need to write the template. Third, connect the template to a file on the client. Finally override the variable where you need it.

Define a default

The default variable definition goes in the module’s manifest file before the class definition. Putting it before the class definition makes sure that it is in scope for overriding in the node definition. The top of the manifest file will look like this:

$heapsize = 1000

class jvm {
...

Note that variables have leading dollar signs.

Write the template

Puppet uses Ruby’s ERB templating system. The template language is powerful, but I’m only going to cover variable substitution here.

Start with putting the configuration file in the templates subdirectory of the module, i.e. <module name>/templates/<config> so that Puppet knows where to find it. To substitute the variables, use < %= name %>. Here the variable name does not start with a dollar sign. Continuing the earlier example, this is part of our template:

export JAVA_OPTS="-Xmx<%= heapsize %>M"

Connecting the template to a file

Using the template in a file declaration is not as simple as just changing the path from the static source. Instead, you have to use the content parameter and the template function. The parameter to the template function is a weird path fragment: the first segment is the module name, and the rest is the path to your file underneath the templates directory. Continuing our example, assuming that the module is named jvm and the template is at modules/jvm/templates/options.erb, this declaration is in the jvm class:

file {"/usr/local/bin/jvm_options.sh":
  mode    => "664",
  content => template("jvm/options.erb"),
}

Notice that the name of the template file doesn’t have to match the target name on the client.

Override the variable

Finally, you have to add a line to the node for the server which needs a different configuration. In the node definition before including the class, redefine the variable to what you need. Example:

node "lowmem" {
  $heapsize = 750
  include jvm
}

Nodes that don’t override the variable will get the default value defined in the module’s manifest file.

Puppet’s templates can do a lot more than simple variable substitution, but this should get you started. Beyond this it’s mostly ERB.

Tags: , ,

Leave a Comment

Make your Linux servers dance with Puppet

Puppet is a system for replicating configurations to many servers, and it makes managing a Linux1 server farm ridiculously easy. One server runs a master process, while the others run a client which connects to the master2 to get the correct configuration. Clients are identified by hostname, so if your servers don’t have resolvable names you’ll need to put them in the hosts file on the master.

Puppet uses a declarative syntax built on top of ruby for defining rules. The documentation is mediocre at best, so you may struggle at first learning how to write the rules. Just read through the example recipes and test it out with a non-production server. The easiest way I found to test a rule is to run

sudo puppetd --test

on the server that should be getting the configuration. It will tell you there if there are any errors.

The version of puppet in Ubuntu 9.10 doesn’t support defining node names with regular expressions, so you might want to grab the version in Debian sid.

I’m still trying to figure out the best way to split up modules and organize my node definitions, so if you’ve used Puppet leave a comment and let me know what you think.


  1. The website also has packages for BSD and MacOS, but I can’t vouch for them. 

  2. By default the clients connect to a host named puppet, so you should either make an DNS entry for your master, or define the name puppet in your clients’ hosts files. 

Tags: , , , ,

Leave a Comment

Bear on the Lamb

Care bear under arrestBear Grylls’s show is getting a little long in the tooth, and the staged “danger situations” are getting more and more ridiculous. I know exactly what Bear needs.

U.S. Marshals.

Every week Bear gets dropped in a wilderness location (like Les Stroud really did) and has to evade U.S. Marshals for seven days. The locals will be told that he’s a real fugitive. Set the dogs on him. Heck, they should shoot him on sight, just to add a bit more excitement. The real fun begins when Bear has to betray his camera crew to buy some more time.

Tags: , ,

Leave a Comment

Nixon’s Back!!

My previous server was unexpectedly destroyed, but after a call to Joe we’re back up and better than ever. Now that I’m actually paying for my space, I’m inspired to dust off this old thing and give it a new go. I also have a lot more time now since I graduated last May.

I plan to start posting a wider variety of content rather than trying to stick to Linux, development, physics, and LaTeX. I’ve become more active on twitter and Facebook, so I’m dumping short stuff there. I also got a tumblr account as a temporary landing site while this one was down, and I think I’ll be keeping it for meaningless drivel that’s between tweet and blog length. I’ll lovingly handcraft longer, meatier, vastly more important drivel for this site. You’ll get more of my personality, my raw thoughts, and let’s be honest, I haven’t quite been prolific with the geeky material to date.

One step towards the personalization of my personal blog has been to import my old LiveJournal posts. These date back to the heady days of 2001 when “blog” was a new term that was still considered a contraction of “web log.” I was a freshly laid-off refugee of the dot-com bust back then, and I was still too dumb to know I’m not funny. There might be some gems in the archives, but as you dig through try not to get lost in the self-important ramblings of an arrogant young man. If the going is too tough, I promise to keep the site updated with a steady stream of self-important ramblings from an arrogant, slightly less young man.

So thanks for looking at the main site after you stumbled across one of my old LaTeX posts. I hope this isn’t the last update for another two years.

FuturamaWeeknights, 9p/8c
Nixon’s Back
www.comedycentral.com
Joke of the DayStand-Up ComedyFree Online Games

Leave a Comment

Better billboarding in Papervision3D

The Papervision3D wiki has an example for making billboarded sprites with just three extra lines of code. Trouble is, it doesn’t really work. Anyone who’s tried it may have noticed that when the planes get too close to the camera, or if the camera rotates around it’s z-axis at all, the planes start rolling instead of staying vertical.

The problem is that the lookAt method defaults to using the world y-axis as “up” for the billboards, which isn’t usually correct. Of course we don’t really care about the world y-axis with billboards. We just want them to be vertical in the camera. Here’s some code that does it.

// calculate the camera vertical in world coordinates
var up : Number3D = new Number3D(0, 1, 0);
Matrix3D.rotateAxis(camera.transform, up);

// billboard is the plane you want to billboard.
billboard.lookAt(viewpoint, up);
billboard.roll(180);
billboard.pitch(180);

Tags: , , , , , , ,

Comments (1)

Protected: An annual ritual

This post is password protected. To view it please enter your password below:

Enter your password to view comments

Last Easter

This is what I started to write last April.  Apparently LJ has a draft saving feature now.  Unfortunately, I didn’t finish it, and it’s not worth finishing now.

It’s been awhile. I don’t feel like covering everything that’s happened just now, so instead I’ll just outline what I earned during Easter.


  1. Catholic Easter mass takes forever


    My sister received full communion into the Catholic church the night before Easter, so I got a cool, three for one bonus: Easter mass, confirmations, and baptisms. Sweet! I can’t tell you how excited I was, but the three (four?) hour ceremony exceeded all my expectations.

  2. There are kids who don’t enjoy hunting for eggs on Easter


    This is the first Easter that Connor is aware of, and my niece was with us too, so we had a lot of fun getting ready.

Comments (1)

Easy Scientific Notation In LaTeX

I use LaTeX for all my physics homework and lab reports, and I’ll be using it for a master’s thesis in the next few years, so I’m constantly adding to my library of LaTeX commands to save some typing. Here’s a good one when you need to use scientific or engineering notation. Put the following in the document preamble (before \begin{document}):


\providecommand{\e}[1]{\ensuremath{\times 10^{#1}}}
 

Then, typing


The [111] crystal planes are 3.2\e{-10} m apart.
 

gives you: The [111] crystal planes are 3.2×10-10 m apart. whether or not you’re already in a math environment. If the exponent is just one number, you can omit the braces, like this: 3\e8 m/s. Cool, huh?

(Of course, for 10-10 m you can just use Angstroms, \AA. If you’re in a math environment, use \text{\AA}, or else the circle won’t line up with the A. That is, if you’re okay with non-SI units.)

Tags: , , , , , ,

Comments (6)

Bold vectors in LaTeX

Vectors can be typeset in LaTeX with the command \vec, which decorates the argument with a little arrow. This was cute at first, but it doesn’t look very good, especially in fractions. Textbooks use bold face for vectors, so here’s how to do that in LaTeX.

\let\oldhat\hat
\renewcommand{\vec}[1]{\mathbf{#1}}
\renewcommand{\hat}[1]{\oldhat{\mathbf{#1}}}

This also makes unit vectors (typeset with \hat) bold.

Tags: , , , , , ,

Comments (5)

Silly Jessica Simpson Game, Pizza Hut Codes

I don’t get it, but my wife loves the celebrity gossip, so when all this stuff about Jessica Simpson started coming out I whipped up this little game to make her laugh. It’s an homage to an old Mac game I haven’t seen in years called “Slick Willie.” I’m also keeping track of Pizza Hut’s sweepstakes codes here. Have fun.

Click on “more” to play the game.

[Read the rest of this entry...]

Tags: , ,

Comments (2)