I have a puppet problem that is specific to the way that Vagrant uses the manifests/modules/hiera-config with its puppet provisioner, since a "puppet apply site.pp" works fine in the resultant vagrant deployed VM (when applied locally in the guest OS itself). In the directory with the Vagrantfile I have a "puppet_files" subdirectory with the manifests, modules, and hiera files that will be copied to /etc/puppet on the VM (I use a puppet module with "file" directives to copy those files there).
My host environment is OSX and I am using vagrant to deploy Centos 6 on VirtualBox.
Background Information:
When I type "vagrant up" I see this to begin with:
==> default: Machine booted and ready!
==> default: Checking for guest additions in VM...
==> default: Setting hostname...
==> default: Mounting shared folders...
default: /vagrant => /Users/juser/vm_stuff/vagrant-fresh
default: /tmp/vagrant-puppet-1/manifests => /Users/juser/vm_stuff/vagrant-fresh/puppet_files/manifests
default: /tmp/vagrant-puppet-1/modules-0 => /Users/juser/vm_stuff/vagrant-fresh/puppet_files/modules
==> default: Running provisioner: shell...
So it looks like it creates temporary files on my OSX filesystem and copies the source directories/files from where I specified in the Vagrantfile. On the VM itself the puppet directory is appropriately mounted as /vagrant/puppet_files. Here is the relevant section of the Vagrantfile for the puppet config:
config.vm.provision "puppet" do |puppet|
puppet.manifests_path = "puppet_files/manifests"
puppet.module_path = "puppet_files/modules"
puppet.hiera_config_path = "puppet_files/hiera_config/hiera.yaml"
puppet.manifest_file = "site.pp"
puppet.options = "--verbose --debug"
end
The site.pp has only two lines of importance (calling two modules):
include ::hierasetup
include ::jboss
And the hiera.yaml file looks like this:
:backends:
- json
:logger: console
:hierarchy:
- "node/%{::fqdn}"
- common
:json:
:datadir: '/etc/puppet/hieradata/'
And my hierasetup module (called in site.pp) also copies a json hiera file to /etc/puppet/hieradata/common.json. And just FYI the jboss module is the module that tries to use hiera with a "hiera_hash" and "create_resources" (which works fine when applied locally/manually in the Linux VM).
The Problem:
Vagrant has no problem importing the manifests and modules and even applying the manifest, but it constantly fails to read my hiera.yaml file (correctly?), because if it did it would see that I specified json and not yaml as the backend:
Debug: importing '/tmp/vagrant-puppet-1/modules-0/hierasetup/manifests/init.pp' in environment production
Debug: Automatically imported hierasetup from hierasetup into production
Debug: importing '/tmp/vagrant-puppet-1/modules-0/jboss/manifests/init.pp' in environment production
Debug: Automatically imported jboss from jboss into production
Debug: hiera(): Hiera YAML backend starting
Debug: hiera(): Looking up jbossas in YAML backend
Debug: hiera(): Looking for data source common
Debug: hiera(): Cannot find datafile /var/lib/hiera/common.yaml, skipping
Error: create_resources(): second argument must be a hash at /tmp/vagrant-puppet-1/modules-0/jboss/manifests/init.pp:14 on node josh-new.morgan.haib.org
Wrapped exception:
create_resources(): second argument must be a hash
Error: create_resources(): second argument must be a hash at /tmp/vagrant-puppet-1/modules-0/jboss/manifests/init.pp:14 on node josh-new.morgan.haib.org
The following SSH command responded with a non-zero exit status.
Vagrant assumes that this means the command failed!
puppet apply --verbose --debug --modulepath '/tmp/vagrant-puppet-1/modules-0:/etc/puppet/modules' --hiera_config=/tmp/vagrant-puppet-1/hiera.yaml --manifestdir /tmp/vagrant-puppet-1/manifests --detailed-exitcodes /tmp/vagrant-puppet-1/manifests/site.pp || [ $? -eq 2 ]
Why is it looking for common.yaml and not /etc/puppet/hieradata/common.json? Why does it think it is a YAML backend and not JSON? It is not reading my hiera.yaml file (which I gave the correct relative path to in the Vagrantfile) and operating on some kind of defaults?
Bottom line: The "puppet apply site.pp" works perfectly if I'm in the Linux environment on the VM applying it locally, but it does not work "the Vagrant way" with the puppet provisioner. I must be missing something about how the hiera config works for Vagrant.
/tmp/vagrant-puppet-1/hiera.yaml
?