I like Puppet with Vagrant. Puppet 4 removed an option I really liked:
You see, often when I’d start a greenfield project, I’d include a
Vagrantfile so getting a new developer set up is one command. I’ve talked about this in the past.
Now-a-days I want to keep my puppet scripts in a folder, organized and slightly away from the main code.
Because I’m boring I call this
manifestdir let me do that: shove everything into
puppet/ and not see it. One simple flag passed into Puppet from Vagrant.
I knew Puppet 4 was going to remove
manifestdir, but I could ignore the problem as long as Vagrant base boxes shipped with Puppet 3.7. Which they no longer do – it seems to be 4.x now-a-days.
Bitrot is rough in the DevOps world.
It also means I had to revisit territory from the first half of an earlier blog post.
I figured out how to solve my problem by abusing Puppet’s Environment system
In my Vagrant setup I’ll have Puppet modules specific to my app: telling Puppet to install this version of Ruby, that database, this Node package, whatever. I’ll also have third party modules: actually doing the heavy lifting of downloading the right Linux package for whatever, etc.
So, I’m building on some abstraction.
puppet module install to pull in third party modules. Puppet 4 puts them in a new place, I specifying the environment, to keep the cognitive dissidence low. I don’t strictly have to do this, but I think it’s good.
Note that we don’t want our third party modules to be in the same places as our specific modules: if installed them in the same place then we’d have to deal with these extra files in our source tree.
You see, when Vagrant starts up it creates a folder:
/tmp/vagrant-puppet/ – it’s a shared folder so anything extra put in there shows up in our source directory.
puppet module install installs third party modules in one place, and Vagrant installs our modules in another place.
Here’s where environments come in:
- We set our
./. This is where Puppet will go looking for environments to load
- We set our
environment– aka the environment Vagrant will tell Puppet to use – to a folder named
puppetin the source directory. (remember that?)
- Puppet environments can contain three things: a config file, a
modulesfolder and a
Our config file sets the path for modules: we tell Puppet to look in our
puppet/modules file, then look in the directory where
puppet module install downloads its modules to, then look at the base module directory.
We need our config file because by default Puppet will look for modules in our environment’s module path, and the base module directory… and not where
puppet module install puts things. (or so it seems…)
So that’s how you mis-use environments to get
manifestdir “working” again.