diff --git a/plugins/provisioners/puppet/config/puppet.rb b/plugins/provisioners/puppet/config/puppet.rb index 47215ca92..568de5fdb 100644 --- a/plugins/provisioners/puppet/config/puppet.rb +++ b/plugins/provisioners/puppet/config/puppet.rb @@ -13,6 +13,7 @@ module VagrantPlugins attr_accessor :manifests_path attr_accessor :environment attr_accessor :environment_path + attr_accessor :environment_variables attr_accessor :module_path attr_accessor :options attr_accessor :synced_folder_type @@ -23,18 +24,19 @@ module VagrantPlugins def initialize super - @binary_path = UNSET_VALUE - @hiera_config_path = UNSET_VALUE - @manifest_file = UNSET_VALUE - @manifests_path = UNSET_VALUE - @environment = UNSET_VALUE - @environment_path = UNSET_VALUE - @module_path = UNSET_VALUE - @options = [] - @facter = {} - @synced_folder_type = UNSET_VALUE - @temp_dir = UNSET_VALUE - @working_directory = UNSET_VALUE + @binary_path = UNSET_VALUE + @hiera_config_path = UNSET_VALUE + @manifest_file = UNSET_VALUE + @manifests_path = UNSET_VALUE + @environment = UNSET_VALUE + @environment_path = UNSET_VALUE + @environment_variables = UNSET_VALUE + @module_path = UNSET_VALUE + @options = [] + @facter = {} + @synced_folder_type = UNSET_VALUE + @temp_dir = UNSET_VALUE + @working_directory = UNSET_VALUE end def nfs=(value) @@ -87,6 +89,10 @@ module VagrantPlugins end end + if @environment_variables == UNSET_VALUE + @environment_variables = {} + end + @binary_path = nil if @binary_path == UNSET_VALUE @module_path = nil if @module_path == UNSET_VALUE @synced_folder_type = nil if @synced_folder_type == UNSET_VALUE diff --git a/plugins/provisioners/puppet/provisioner/puppet.rb b/plugins/provisioners/puppet/provisioner/puppet.rb index dcf6863aa..9f8912b7b 100644 --- a/plugins/provisioners/puppet/provisioner/puppet.rb +++ b/plugins/provisioners/puppet/provisioner/puppet.rb @@ -207,7 +207,7 @@ module VagrantPlugins options = options.join(" ") # Build up the custom facts if we have any - facter = "" + facter = nil if !config.facter.empty? facts = [] config.facter.each do |key, value| @@ -219,7 +219,7 @@ module VagrantPlugins facts.map! { |v| "$env:#{v};" } end - facter = "#{facts.join(" ")} " + facter = facts.join(" ") end puppet_bin = "puppet" @@ -227,7 +227,28 @@ module VagrantPlugins puppet_bin = File.join(@config.binary_path, puppet_bin) end - command = "#{facter} #{puppet_bin} apply #{options}" + env_vars = nil + if !config.environment_variables.nil? && !config.environment_variables.empty? + env_vars = config.environment_variables.map do |env_key, env_value| + "#{env_key}=\"#{env_value}\"" + end + + if windows? + env_vars.map! do |env_var_string| + "$env:#{env_var_string}" + end + end + + env_vars = env_vars.join(" ") + end + + command = [ + env_vars, + facter, + puppet_bin, + "apply", + options + ].compact.map(&:to_s).join(" ") if config.working_directory if windows? command = "cd #{config.working_directory}; if ($?) \{ #{command} \}" diff --git a/website/source/docs/provisioning/puppet_apply.html.md b/website/source/docs/provisioning/puppet_apply.html.md index 2de1c1542..cf1a69461 100644 --- a/website/source/docs/provisioning/puppet_apply.html.md +++ b/website/source/docs/provisioning/puppet_apply.html.md @@ -52,6 +52,9 @@ available below this section. * `environment_path` (string) - Path to the directory that contains environment files on the host disk. +* `environment_variables` (hash) - A hash of string key/value pairs to be set as + environment variables before the puppet apply run. + * `options` (array of strings) - Additionally options to pass to the Puppet executable when running Puppet.