Over a million developers have joined DZone.

Effective Puppet Module Management in Vagrant

· DevOps Zone

The DevOps Zone is brought to you in partnership with Sonatype Nexus. The Nexus Suite helps scale your DevOps delivery with continuous component intelligence integrated into development tools, including Eclipse, IntelliJ, Jenkins, Bamboo, SonarQube and more. Schedule a demo today

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.

The DevOps Zone is brought to you in partnership with Sonatype Nexus. Use the Nexus Suite to automate your software supply chain and ensure you're using the highest quality open source components at every step of the development lifecycle. Get Nexus today

Topics:

Published at DZone with permission of James Carr, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}