From ffcb58bcd90a2221bdd338c2181fd5c1f334247b Mon Sep 17 00:00:00 2001 From: Ben Hines Date: Sun, 12 Apr 2015 12:31:31 -0700 Subject: [PATCH] When using environments, allow specifying the 'main manifest' using manifest_path and manifest_file. --- plugins/provisioners/puppet/config/puppet.rb | 38 ++++++++----------- .../provisioners/puppet/provisioner/puppet.rb | 20 +++++----- templates/locales/en.yml | 4 -- 3 files changed, 27 insertions(+), 35 deletions(-) diff --git a/plugins/provisioners/puppet/config/puppet.rb b/plugins/provisioners/puppet/config/puppet.rb index 56b7a4a0f..99b06face 100644 --- a/plugins/provisioners/puppet/config/puppet.rb +++ b/plugins/provisioners/puppet/config/puppet.rb @@ -59,24 +59,18 @@ module VagrantPlugins def finalize! super - if @environment_path == UNSET_VALUE - if @manifests_path == UNSET_VALUE - if 1 #If both are unset, assume 'environment' mode. - @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 + if @environment_path == UNSET_VALUE && @manifests_path == UNSET_VALUE + #If both are unset, assume 'manifests' mode for now. TBD: Switch to environments by default? + @manifests_path = [:host, "manifests"] 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 if @environment_path == UNSET_VALUE @@ -86,8 +80,12 @@ module VagrantPlugins else @environment_path[0] = @environment_path[0].to_sym @environment = "production" if @environment == UNSET_VALUE - @manifest_file = nil - @manifests_path = nil + if @manifests_path == UNSET_VALUE + @manifests_path = nil + end + if @manifest_file == UNSET_VALUE + @manifest_file = nil + end end @binary_path = nil if @binary_path == UNSET_VALUE @@ -118,10 +116,6 @@ module VagrantPlugins # Calculate the manifests and module paths based on env 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 if manifests_path != nil && manifests_path[0].to_sym == :host expanded_path = Pathname.new(manifests_path[1]). diff --git a/plugins/provisioners/puppet/provisioner/puppet.rb b/plugins/provisioners/puppet/provisioner/puppet.rb index b205b6b79..e68f8fa85 100644 --- a/plugins/provisioners/puppet/provisioner/puppet.rb +++ b/plugins/provisioners/puppet/provisioner/puppet.rb @@ -39,8 +39,8 @@ module VagrantPlugins File.expand_path(@config.environment_path[1], root_path), environments_guest_path, folder_opts) end - else - # Non-Environment mode + end + if @config.manifest_file @manifest_file = File.join(manifests_guest_path, @config.manifest_file) # Share the manifests directory with the guest if @config.manifests_path[0].to_sym == :host @@ -63,8 +63,8 @@ module VagrantPlugins if type == :stdout # Parse out the environment manifest path since puppet apply doesnt do that for us. if data =~ /\s+manifest\s+=\s(.*)/ - @environment_manifest_path = $1 - @environment_manifest_path.gsub! '$basemodulepath:', "#{environments_guest_path}/#{@config.environment}/" + @manifest_file = $1 + @manifest_file.gsub! '$basemodulepath:', "#{environments_guest_path}/#{@config.environment}/" end end end @@ -78,13 +78,17 @@ module VagrantPlugins @machine.guest.capability(:wait_for_reboot) 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 = [] if @config.manifests_path.is_a?(Array) && @config.manifests_path[0] == :host check << manifests_guest_path end 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 end @module_paths.each do |host_path, guest_path| @@ -111,7 +115,6 @@ module VagrantPlugins @machine.communicate.upload(local_hiera_path, @hiera_config_path) end - parse_environment_metadata run_puppet_apply end @@ -181,15 +184,14 @@ module VagrantPlugins options << "--detailed-exitcodes" if config.environment_path - options << " #{@environment_manifest_path}" options << "--environmentpath #{environments_guest_path}/" options << "--environment #{@config.environment}" else options << "--manifestdir #{manifests_guest_path}" - options << @manifest_file end + + options << @manifest_file options = options.join(" ") - @machine.ui.info("Running ye puppet apply with options #{options}") # Build up the custom facts if we have any diff --git a/templates/locales/en.yml b/templates/locales/en.yml index 8ddc475db..f3782cdbf 100644 --- a/templates/locales/en.yml +++ b/templates/locales/en.yml @@ -1864,10 +1864,6 @@ en: Please specify a path to an existing Puppet directory environment. 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}" - 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: |- Shared folders that Puppet requires are missing on the virtual machine. This is usually due to configuration changing after already booting the