When using environments, allow specifying the 'main manifest' using manifest_path and manifest_file.

This commit is contained in:
Ben Hines 2015-04-12 12:31:31 -07:00
parent 0efb9a3932
commit ffcb58bcd9
3 changed files with 27 additions and 35 deletions

View File

@ -59,24 +59,18 @@ module VagrantPlugins
def finalize! def finalize!
super super
if @environment_path == UNSET_VALUE if @environment_path == UNSET_VALUE && @manifests_path == UNSET_VALUE
if @manifests_path == UNSET_VALUE #If both are unset, assume 'manifests' mode for now. TBD: Switch to environments by default?
if 1 #If both are unset, assume 'environment' mode. @manifests_path = [:host, "manifests"]
@environment_path = [:host, "environments"]
else
@manifests_path = [:host, "manifests"]
end
end
if @manifests_path != UNSET_VALUE && !@manifests_path.is_a?(Array)
@manifests_path = [:host, @manifests_path]
end
else
if @environment_path != UNSET_VALUE && !@environment_path.is_a?(Array)
@environment_path = [:host, @environment_path]
end
end end
# If the paths are just strings, assume they are 'host' paths (rather than guest)
if @environment_path != UNSET_VALUE && !@environment_path.is_a?(Array)
@environment_path = [:host, @environment_path]
end
if @manifests_path != UNSET_VALUE && !@manifests_path.is_a?(Array)
@manifests_path = [:host, @manifests_path]
end
@hiera_config_path = nil if @hiera_config_path == UNSET_VALUE @hiera_config_path = nil if @hiera_config_path == UNSET_VALUE
if @environment_path == UNSET_VALUE if @environment_path == UNSET_VALUE
@ -86,8 +80,12 @@ module VagrantPlugins
else else
@environment_path[0] = @environment_path[0].to_sym @environment_path[0] = @environment_path[0].to_sym
@environment = "production" if @environment == UNSET_VALUE @environment = "production" if @environment == UNSET_VALUE
@manifest_file = nil if @manifests_path == UNSET_VALUE
@manifests_path = nil @manifests_path = nil
end
if @manifest_file == UNSET_VALUE
@manifest_file = nil
end
end end
@binary_path = nil if @binary_path == UNSET_VALUE @binary_path = nil if @binary_path == UNSET_VALUE
@ -118,10 +116,6 @@ module VagrantPlugins
# Calculate the manifests and module paths based on env # Calculate the manifests and module paths based on env
this_expanded_module_paths = expanded_module_paths(machine.env.root_path) this_expanded_module_paths = expanded_module_paths(machine.env.root_path)
if environment_path != nil && manifests_path != nil
errors << I18n.t("vagrant.provisioners.puppet.environment_manifest_conflict")
end
# Manifests path/file validation # Manifests path/file validation
if manifests_path != nil && manifests_path[0].to_sym == :host if manifests_path != nil && manifests_path[0].to_sym == :host
expanded_path = Pathname.new(manifests_path[1]). expanded_path = Pathname.new(manifests_path[1]).

View File

@ -39,8 +39,8 @@ module VagrantPlugins
File.expand_path(@config.environment_path[1], root_path), File.expand_path(@config.environment_path[1], root_path),
environments_guest_path, folder_opts) environments_guest_path, folder_opts)
end end
else end
# Non-Environment mode if @config.manifest_file
@manifest_file = File.join(manifests_guest_path, @config.manifest_file) @manifest_file = File.join(manifests_guest_path, @config.manifest_file)
# Share the manifests directory with the guest # Share the manifests directory with the guest
if @config.manifests_path[0].to_sym == :host if @config.manifests_path[0].to_sym == :host
@ -63,8 +63,8 @@ module VagrantPlugins
if type == :stdout if type == :stdout
# Parse out the environment manifest path since puppet apply doesnt do that for us. # Parse out the environment manifest path since puppet apply doesnt do that for us.
if data =~ /\s+manifest\s+=\s(.*)/ if data =~ /\s+manifest\s+=\s(.*)/
@environment_manifest_path = $1 @manifest_file = $1
@environment_manifest_path.gsub! '$basemodulepath:', "#{environments_guest_path}/#{@config.environment}/" @manifest_file.gsub! '$basemodulepath:', "#{environments_guest_path}/#{@config.environment}/"
end end
end end
end end
@ -78,13 +78,17 @@ module VagrantPlugins
@machine.guest.capability(:wait_for_reboot) @machine.guest.capability(:wait_for_reboot)
end end
# In environment mode we still need to specify a manifest file, if its not, use the one from env config if specified.
if !@manifest_file
@manifest_file = "#{environments_guest_path}/#{@config.environment}/manifests/site.pp"
parse_environment_metadata
end
# Check that the shared folders are properly shared # Check that the shared folders are properly shared
check = [] check = []
if @config.manifests_path.is_a?(Array) && @config.manifests_path[0] == :host if @config.manifests_path.is_a?(Array) && @config.manifests_path[0] == :host
check << manifests_guest_path check << manifests_guest_path
end end
if @config.environment_path.is_a?(Array) && @config.environment_path[0] == :host if @config.environment_path.is_a?(Array) && @config.environment_path[0] == :host
@environment_manifest_path = "#{environments_guest_path}/#{@config.environment}/manifests/site.pp"
check << environments_guest_path check << environments_guest_path
end end
@module_paths.each do |host_path, guest_path| @module_paths.each do |host_path, guest_path|
@ -111,7 +115,6 @@ module VagrantPlugins
@machine.communicate.upload(local_hiera_path, @hiera_config_path) @machine.communicate.upload(local_hiera_path, @hiera_config_path)
end end
parse_environment_metadata
run_puppet_apply run_puppet_apply
end end
@ -181,15 +184,14 @@ module VagrantPlugins
options << "--detailed-exitcodes" options << "--detailed-exitcodes"
if config.environment_path if config.environment_path
options << " #{@environment_manifest_path}"
options << "--environmentpath #{environments_guest_path}/" options << "--environmentpath #{environments_guest_path}/"
options << "--environment #{@config.environment}" options << "--environment #{@config.environment}"
else else
options << "--manifestdir #{manifests_guest_path}" options << "--manifestdir #{manifests_guest_path}"
options << @manifest_file
end end
options << @manifest_file
options = options.join(" ") options = options.join(" ")
@machine.ui.info("Running ye puppet apply with options #{options}") @machine.ui.info("Running ye puppet apply with options #{options}")
# Build up the custom facts if we have any # Build up the custom facts if we have any

View File

@ -1864,10 +1864,6 @@ en:
Please specify a path to an existing Puppet directory environment. Please specify a path to an existing Puppet directory environment.
environment_path_missing: "The environment path specified for Puppet does not exist: %{path}" environment_path_missing: "The environment path specified for Puppet does not exist: %{path}"
manifests_path_missing: "The manifests path specified for Puppet does not exist: %{path}" manifests_path_missing: "The manifests path specified for Puppet does not exist: %{path}"
environment_manifest_conflict: |-
You may not specify both environment_path and manifests_path.
Please specify environment and environment_path without manifests_path, or
manifests_path without environment_path (deprecated).
missing_shared_folders: |- missing_shared_folders: |-
Shared folders that Puppet requires are missing on the virtual machine. Shared folders that Puppet requires are missing on the virtual machine.
This is usually due to configuration changing after already booting the This is usually due to configuration changing after already booting the