Best Practices for Building Puppet Modules
Does the term “best practices” make your skin crawl? It makes Gary Larizza’s skin crawl, too. As he says, “one person’s best practice is another person’s ‘What the **** did you just do?’” (Yeah, that’s edited because this is a family newspaper — er, blog.)
Nonetheless, Gary, a professional services engineer here at Puppet Labs, offers some best practices for building Puppet modules on his blog. Here’s a quick summary of his recent three-parter, which is a great introduction to Gary’s blog, if you haven’t already added it to your regular Puppet reading. Gary’s penchant for couching helpful advice in an amusingly self-deprecating style makes his blog as fun as it is useful.
Part 1: Module structure. Gary talks about what you need to make a good component module, and adds some “gotchas” he’s noticed over time. For example, he recommends treating parameters as, essentially, the API to your module. Gary also recommends keeping component modules generic, and not adding Hiera calls inside them. There’s a lot more in this post, including strong advice to store all your modules in version control.
Part 2: Roles and profiles. You should be able to classify a node with just a single role, Gary says, and include profiles in roles. There’s a lot of specific advice in this post on using roles & profiles to classify servers, including how to distinguish two machines that are very similar, but not the same.
Part 3: Dynamic environments with R10k. Gary discusses the value of dynamic environments and R10k for iterating on your Puppet modules. If you haven't heard about R10k, it’s an invention by another Puppet employee, Adrien Thebo. You can read about it straight from the original source right here.
- You'll find more advice about writing great modules on the Puppet Forge.
- If you want to build custom types and providers, Gary Larizza can help you with that, too.
- Puppet Enterprise includes some useful modules that have already been rigorously tested and are maintained for the long term. Download it and try it out for free today.