From 73bff1b45738412b0a66c4c9a67955d7525358a0 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Wed, 11 Jan 2012 09:48:18 -0800 Subject: [PATCH] Fix up puppet provisioner a bit --- lib/vagrant/provisioners/puppet.rb | 33 ++++++++++++++++-------------- templates/locales/en.yml | 3 ++- 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/lib/vagrant/provisioners/puppet.rb b/lib/vagrant/provisioners/puppet.rb index 2142c5678..fcec32c6e 100644 --- a/lib/vagrant/provisioners/puppet.rb +++ b/lib/vagrant/provisioners/puppet.rb @@ -1,3 +1,5 @@ +require "log4r" + module Vagrant module Provisioners class PuppetError < Vagrant::Errors::VagrantError @@ -26,12 +28,6 @@ module Vagrant Pathname.new(manifests_path).expand_path(env.root_path) end - # Returns the manifest file if set otherwise returns the box name pp file - # which may or may not exist. - def computed_manifest_file - manifest_file || "#{top.vm.box}.pp" - end - # Returns the module paths as an array of paths expanded relative to the # root path. def expanded_module_paths(env) @@ -55,11 +51,6 @@ module Vagrant if !this_expanded_manifests_path.directory? errors.add(I18n.t("vagrant.provisioners.puppet.manifests_path_missing", :path => this_expanded_manifests_path)) - else - if !this_expanded_manifests_path.join(computed_manifest_file).file? - errors.add(I18n.t("vagrant.provisioners.puppet.manifest_missing", - :manifest => computed_manifest_file)) - end end # Module paths validation @@ -75,10 +66,21 @@ module Vagrant Config end + def initialize(env, config) + super + + @logger = Log4r::Logger.new("vagrant::provisioners::puppet") + end + def prepare # Calculate the paths we're going to use based on the environment - @expanded_manifests_path = config.expanded_manifests_path(env) - @expanded_module_paths = config.expanded_module_paths(env) + @expanded_manifests_path = config.expanded_manifests_path(env[:vm].env) + @expanded_module_paths = config.expanded_module_paths(env[:vm].env) + @manifest_file = config.manifest_file || "#{env[:vm].config.vm.box}.pp" + + if !@expanded_manifests_path.join(@manifest_file).exist? + raise PuppetError, :manifest_missing, :manifest => @manifest_file + end set_module_paths share_manifests @@ -134,12 +136,13 @@ module Vagrant def run_puppet_client options = [config.options].flatten options << "--modulepath '#{@module_paths.values.join(':')}'" if !@module_paths.empty? - options << config.computed_manifest_file + options << @manifest_file options = options.join(" ") command = "cd #{manifests_guest_path} && puppet apply #{options}" - env[:ui].info I18n.t("vagrant.provisioners.puppet.running_puppet", :manifest => config.computed_manifest_file) + env[:ui].info I18n.t("vagrant.provisioners.puppet.running_puppet", + :manifest => @manifest_file) env[:vm].channel.sudo(command) do |type, data| # Output the data with the proper color based on the stream. diff --git a/templates/locales/en.yml b/templates/locales/en.yml index 636feb57c..352d45d2a 100644 --- a/templates/locales/en.yml +++ b/templates/locales/en.yml @@ -596,7 +596,8 @@ en: installed on this guest. Puppet provisioning can not continue without Puppet properly installed. running_puppet: "Running Puppet with %{manifest}..." - manifest_missing: "The Puppet %{manifest} manifest is missing. You cannot configure this box." + manifest_missing: |- + The Puppet %{manifest} manifest is missing. You cannot configure this box. manifests_path_missing: "The manifests path specified for Puppet does not exist: %{path}" missing_shared_folders: |- Shared folders that Puppet requires are missing on the virtual machine.