Puppet 2.7.19
Vagrant version 1.0.6
VM OS Ubuntu 12.04
I am attempting to set the puppet module path from vagrant. Which seems like it should be very simple.
In my Vagrant file I have:
Vagrant::Config.run do |config|
config.vm.provision :puppet, :module_path => "my_modules"
config.vm.provision :puppet, :options => ["--modulepath", "my_modules"]
end
When I change the the value of the modulepath it seems to have no effect (after vagrant reload
)
Here is a snipplet from vagrant up
[default] -- v-root: /vagrant
[default] -- manifests: /tmp/vagrant-puppet/manifests
[default] -- v-pp-m0: /tmp/vagrant-puppet/modules-0
Notice the /tmp/vagrant-puppet/modules-0
? What is this about?
Then from inside vagrant:
vagrant@precise64:~$ puppet apply --configprint modulepath
/home/vagrant/.puppet/modules:/usr/share/puppet/modules
So when I do: puppet module install puppetlabs/mysql
I get this error:
Preparing to install into /home/vagrant/.puppet/modules ...
Error: Could not install module 'puppetlabs-mysql' (latest)
Directory /home/vagrant/.puppet/modules does not exist
So I have to:
vagrant@precise64:~/.puppet$ mkdir /home/vagrant/.puppet/modules
vagrant@precise64:~/.puppet$ puppet module install puppetlabs/mysql
Preparing to install into /home/vagrant/.puppet/modules ...
Downloading from http://forge.puppetlabs.com ...
Installing -- do not interrupt ...
/home/vagrant/.puppet/modules
└─┬ puppetlabs-mysql (v0.6.1)
└── puppetlabs-stdlib (v3.2.0)
And then I have to move the modules into place where vagrant can see them...
mv /home/vagrant/.puppet/modules/mysql /tmp/vagrant-puppet/modules-0
Seems like maybe this is a bug or I am really missing something. Seems pretty basic so I would like to hear how others solved this.
Thanks!
You're effectively specifying module_path twice:
Vagrant::Config.run do |config|
config.vm.provision :puppet, :module_path => "my_modules"
config.vm.provision :puppet, :options => ["--modulepath", "my_modules"]
end
I'm not sure which would wind up overriding the other, but you shouldn't be specifying the module path in both ways.
I think it's better to use vagrant's support for module_path in preference to the :options
array, as in your first line. I like the following style better still:
Vagrant::Config.run do |config|
...
config.vm.provision :puppet do |puppet|
puppet.manifests_path = "manifests"
puppet.module_path = ["modules-contrib","modules-custom"]
puppet.manifest_file = "site.pp"
end # puppet
end # config
You asked about /tmp/vagrant-puppet/modules-0
. That's the first item in the modulepath array, where the 0
is the array index. Ie in my example above, the modules-contrib
and modules-custom
directories from my vagrant project get mounted at /tmp/vagrant-puppet/modules-0
and /tmp/vagrant-puppet/modules-1
respectively.
You shouldn't be installing puppet modules within the vagrant box. Instead, install them in a modules directory in your vagrant project in the host environment.
Rather than installing them one by one, I'd recommend using librarian puppet (gem install librarian-puppet
), and putting a Puppetfile
in your vagrant project, which lists all the third party modules you want, and tells librarian-puppet to put them in a separate modules directory from the one you use for your custom puppet modules. I use the modules-contrib
directory for third party modules, and put my own in modules-custom
.
Tell the librarian where to put its modules:
librarian-puppet config --local path modules-contrib
See https://github.com/rodjek/librarian-puppet for the layout of the Puppetfile. It's pretty simple, and lets you mix up puppet-forge and git sources as you like.
You should add the modules-contrib
folder to your .gitignore
file (assuming you use git), and rely on version control of the Puppetfile
file.
As it reads from Vagrant Documentation:
The Vagrant Puppet provisioner allows you to mount a local folder of modules onto the VM, and will configure Puppet to be aware of them, automatically.
The local folder refers to a folder on your host machine.
And then:
The module path is expanded relative to the folder containing the Vagrantfile.
The folder containing your VagrantFile is on your host machine.
So, you're trying to use an option that sets a path to a folder on the host machine to control the path to a folder on the VM.
You have to put your modules on the host machine, not on the VM. Here's an example:
HOST MACHINE
~/Dev/mybox/ -> base path of the "mybox" Vagrant VM
~/Dev/mybox/VagrantFile -> Vagrant file that controls "mybox"
~/Dev/mybox/puppet/modules -> path to the puppet modules used on "mybox"
~/Dev/mybox/puppet/modules/apache -> path of the apache module to be applied on "mybox"
VagrantFile:
# Enable puppet provisioning
config.vm.provision :puppet do |puppet|
puppet.module_path = "puppet/modules"
puppet.manifests_path = "puppet"
puppet.manifest_file = "mybox.pp"
end
VIRTUAL MACHINE
When I start mybox:
[default] Mounting shared folders...
[default] -- v-root: /vagrant
[default] -- manifests: /tmp/vagrant-puppet/manifests
[default] -- v-pp-m0: /tmp/vagrant-puppet/modules-0
then
vagrant@mybox:~$ cd /tmp/vagrant-puppet/modules-0
vagrant@mybox:/tmp/vagrant-puppet/modules-0$ ls
apache
As you can see the ~/Dev/mybox/puppet/modules/apache directory on the host machine was mounted on /tmp/vagrant-puppet/modules-0 on the Vagrant VM.
Hope this helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With