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

└── 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:""

    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"

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?



I changed

puppet.manifests_path = "puppet/environments/#{env}/manifests" 

and removed puppet.working_directory to have my VM up/provision.


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:

srv.vm.provision :puppet do |puppet|
      puppet.working_directory = "/vagrant/puppet"
      puppet.module_path       = "puppet/modules"
      puppet.manifests_path    = "puppet/manifests"
      puppet.manifest_file     = "site.pp"
      puppet.hiera_config_path = "puppet/hiera.yaml"
      puppet.options           = "--debug --verbose --environment #{env}"

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:

env = "production"

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:

Vagrant.configure(2) do |config|
  config.vm.box = "centos7"
  config.vm.synced_folder("../../puppet/trunk/server/hieradata", "/etc/puppet/hieradata")
  config.vm.provision "puppet" do |puppet|
    puppet.environment       = "dev"
    puppet.environment_path  = "../../puppet/trunk/server/environments"
    puppet.hiera_config_path = "../../puppet/trunk/server/hiera.yaml"
    puppet.module_path       = [ "../../puppet/trunk/server/environments/dev/modules", "../../puppet/trunk/server/modules" ]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.