Merge pull request #7931 from chrisroberts/puppet/env-vars

Puppet environment variables
This commit is contained in:
Chris Roberts 2016-10-28 12:46:44 -07:00 committed by GitHub
commit 05963159a8
3 changed files with 45 additions and 15 deletions

View File

@ -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

View File

@ -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} \}"

View File

@ -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.