I use Puppet 3.7 in standard client-server mode, with environments, and using Hiera for data. I use Vagrant to test the Puppet manifests directly from my Puppet repository.
I recently started to use Hiera and changed my Vagrantfile (and Vagrant directory) to works with it. It now seems to work with Hiera but another problem appears: Vagrant thinks my VM is in environment production when it's in experimental one. (this worked fine before)
The Puppet repository looks like
~/code/puppet
└── environments
├── experimental
│ ├── manifests
│ │ └── site.pp
│ ├── modules
│ └── Puppetfile
├── production
│ ├── manifests
│ │ └── site.pp
│ ├── modules
│ └── Puppetfile
└── testing
├── manifests
│ └── site.pp
├── modules
└── Puppetfile
My Vagrant setup is stored in another directory. I have created a symbolic link (ln -s) to ~/code/puppet named puppet in this directory. The Vagrantfile looks
config.vm.define "standalone", primary: true do |config|
config.vm.box = "debian_wheezy+vbox_jessie+puppet_3.7"
config.vm.hostname = "standalone.puppet.vagrant"
config.vm.network "private_network", ip:"192.168.10.21"
config.vm.synced_folder "puppet/hieradata", "/etc/puppet/hieradata"
config.vm.provision :puppet, :options => ["--yamldir /hieradata"] do |puppet|
puppet.manifests_path = "puppet/environments/experimental/manifests"
puppet.manifest_file = "site.pp"
puppet.module_path = [ "puppet/environments/experimental/modules", "puppet/environments/production/modules", "puppet/modules" ]
puppet.hiera_config_path = "puppet/hiera.yaml"
end
end
I imagine that my recent changes following the use of Hiera are not correct to Vagrant, and maybe the hacks (linking puppet code directory) are the cause, but I can't see how this should be organized.
Is there some people who knows this problem and how to solve it?
Thanks
Update
I changed
puppet.manifests_path = "puppet/environments/#{env}/manifests"
and removed puppet.working_directory to have my VM up/provision.
With
puppet.module_path = [ "puppet/modules", "puppet/environments/production/modules" ]
it seems to let my VM access to production and current env modules, which I need.
You can specify all options for your puppet run. You can use something like this:
Which means that your modules are in "puppet/modules/#{env} and your manifests in "puppet/manifests/#{env}. Now, "env" is a variable that you can set in your Vagrantfile:
or: you could put all variables, like "env", in a yaml file and load that.
For reference, you can find all puppet provision options here: https://www.vagrantup.com/docs/provisioning/puppet_apply.html
I came here looking to solve a similar issue. I was able to concatenate more than one modulepath by using an Array. So that modulepath will become
modulepath = ../puppet/environments/dev/modules:../puppet/modules
Your paths will vary.
My vagrant environment will always be
dev
so I am fine hard-coding this modulepath here.My Vagrantfile looks like this: