I’ve started publishing as many of my Puppet modules as possible on Puppet Forge. It isn’t hard to do but there are a few things to know. This guide is largely based on Puppetlabs’ own guide Publishing Modules on the Puppet Forge.
- For home-grown modules that have grown organically, you are likely to have at least some site-specific data mixed in with the code. Before publishing, you’ll need to abstract this out. I recommend using parametrised classes with sane defaults for your inputs. If necessary, you can have a local wrapper class to pass site-specific values into your module.
- The vast majority of Puppet modules are on GitHub, but this isn’t actually a requirement. GitHub offers public collaboration and issue tracking, but you can keep your code wherever you like.
- Before you can publish, you need to include some metadata with your module. Look at the output of
puppet module generate. If you’re starting from scratch, this command is an excellent place to start. If you’re patching up an old module for publication, run it in a different location and selectively copy the useful files into your module. The mandatory files are
- When you’re ready to publish, run
puppet module build. This creates a tarball of your module and metadata which is ready to upload to Puppet Forge.
- Create an account on Puppet Forge and upload your tarball. It will automatically fill in the metadata.
- Install your module on your Puppetmaster by doing
puppet module install myname/mymodule
I think point 1 is a good driver for publishing forge modules. Abstracting out local data is good for all sorts of reasons, and making our forge modules public forces us to do that.
It helps to keep us from being lazy, and should make our environment cleaner in the long run (If only we’d started doing it years ago, we wouldn’t have a backlog of modules to pick through!)