From 6e4a9e15f7655233614dd9c328b46bdd111c610d Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Wed, 1 May 2013 18:44:18 -0700 Subject: [PATCH] Puppet provisioner supports hiera by specifying hiera_config_path --- CHANGELOG.md | 1 + plugins/provisioners/puppet/config/puppet.rb | 3 +++ .../provisioners/puppet/provisioner/puppet.rb | 22 ++++++++++++++++++- 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a8ac5588e..411545468 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ FEATURES: + - Puppet provisioner now supports Hiera by specifying a `hiera_config_path`. - Added a `working_directory` configuration option to the Puppet apply provisioner so you can specify the working directory when `puppet` is called, making it friendly to Hiera data and such. [GH-1670] diff --git a/plugins/provisioners/puppet/config/puppet.rb b/plugins/provisioners/puppet/config/puppet.rb index 9c1a39389..c114ad900 100644 --- a/plugins/provisioners/puppet/config/puppet.rb +++ b/plugins/provisioners/puppet/config/puppet.rb @@ -3,6 +3,7 @@ module VagrantPlugins module Config class Puppet < Vagrant.plugin("2", :config) attr_accessor :facter + attr_accessor :hiera_config_path attr_accessor :manifest_file attr_accessor :manifests_path attr_accessor :module_path @@ -13,6 +14,7 @@ module VagrantPlugins def initialize super + @hiera_config_path = UNSET_VALUE @manifest_file = UNSET_VALUE @manifests_path = UNSET_VALUE @module_path = UNSET_VALUE @@ -25,6 +27,7 @@ module VagrantPlugins def finalize! super + @hiera_config_path = nil if @hiera_config_path == UNSET_VALUE @manifest_file = "default.pp" if @manifest_file == UNSET_VALUE @manifests_path = "manifests" if @manifests_path == UNSET_VALUE @module_path = nil if @module_path == UNSET_VALUE diff --git a/plugins/provisioners/puppet/provisioner/puppet.rb b/plugins/provisioners/puppet/provisioner/puppet.rb index 4fc9d1eb4..485abd7bb 100644 --- a/plugins/provisioners/puppet/provisioner/puppet.rb +++ b/plugins/provisioners/puppet/provisioner/puppet.rb @@ -52,6 +52,21 @@ module VagrantPlugins # Verify Puppet is installed and run it verify_binary("puppet") + + # Make sure the temporary directory is properly set up + @machine.communicate.tap do |comm| + comm.sudo("mkdir -p #{config.temp_dir}") + comm.sudo("chmod 0777 #{config.temp_dir}") + end + + # Upload Hiera configuration if we have it + @hiera_config_path = nil + if config.hiera_config_path + local_hiera_path = File.expand_path(config.hiera_config_path, @machine.env.root_path) + @hiera_config_path = File.join(config.temp_dir, "hiera.yaml") + @machine.communicate.upload(local_hiera_path, @hiera_config_path) + end + run_puppet_apply end @@ -78,6 +93,11 @@ module VagrantPlugins options << "--modulepath '#{module_paths.join(':')}'" end + if @hiera_config_path + options << "--hiera_config=#{@hiera_config_path}" + end + + options << "--detailed-exitcodes" options << @manifest_file options = options.join(" ") @@ -92,7 +112,7 @@ module VagrantPlugins facter = "#{facts.join(" ")} " end - command = "#{facter}puppet apply #{options} --detailed-exitcodes || [ $? -eq 2 ]" + command = "#{facter}puppet apply #{options} || [ $? -eq 2 ]" if config.working_directory command = "cd #{config.working_directory} && #{command}" end