I still remember my first early forays into using vagrant and puppet together to provision local development environments. Everything was easy accept figuring out a proper way to bundle puppet modules with a project. Basically it was a three step phase of discovery.
1. Run “puppet module install” and adding them to the git repo (not a bright est idea but simple).
2. Add puppet modules as git submodules in the project. This turned out to be even more troublesome as adding/removing/updating modules became a real pain.
3. Use puppet-librarian to manage puppet modules as the dependencies they are.
The third option was the best… we could now just simply add, remove or upgrade puppet module versions in a Puppetfile and just run “librarian-puppet install” to install the modules. But a final caveat wound up being that users had to install rubygems on their host machine which can bring other troubles. So why not just install the modules within the vagrant box when it comes up and be done with it?
Vagrant.configure("2") do |config| config.vm.synced_folder ".", "/home/vagrant/my-project", :nfs => true config.vm.provision "shell", inline: "gem install librarian-puppet" config.vm.provision "shell", inline: "cp /home/vagrant/my-project/Puppetfile /tmp" config.vm.provision "shell", inline: "cd /tmp && librarian-puppet install --verbose" config.vm.provision "puppet" do |puppet| puppet.temp_dir = "/tmp" puppet.options = ['--modulepath=/tmp/modules'] end end
This effectively adds the Puppetfile in the root of the project to the guest machine and installs the modules, referencing the modules directory when running puppet apply. This works great as you can guarantee the same install across multiple environments where developers may or may not be familiar with rubygems.