From d0e3cf1210abbf68d93472d19bd02a10bd484e18 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Tue, 14 Dec 2010 21:57:12 -0800 Subject: [PATCH] config.puppet.options can be a string as well --- CHANGELOG.md | 1 + lib/vagrant/provisioners/puppet.rb | 8 +++++--- test/vagrant/provisioners/puppet_test.rb | 14 ++++++++++---- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6f1ca6150..b16e86782 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ - Solaris system registered, so it can be set with `:solaris`. - `vagrant package` include can be a directory name, which will cause the contents to be recursively copied into the package. [GH-241] + - Arbitrary options to puppet binary can be set with `config.puppet.options`. [GH-242] ## 0.6.8 (November 30, 2010) diff --git a/lib/vagrant/provisioners/puppet.rb b/lib/vagrant/provisioners/puppet.rb index 2365ce177..5dc5d0a92 100644 --- a/lib/vagrant/provisioners/puppet.rb +++ b/lib/vagrant/provisioners/puppet.rb @@ -64,11 +64,13 @@ module Vagrant return @manifest else raise PuppetError.new(:_key => :manifest_missing, :manifest => @manifest) - end - end + end + end def run_puppet_client - command = "cd #{env.config.puppet.pp_path} && sudo -E puppet #{env.config.puppet.options.join(" ")} #{@manifest}" + options = env.config.puppet.options + options = options.join(" ") if options.is_a?(Array) + command = "cd #{env.config.puppet.pp_path} && sudo -E puppet #{options} #{@manifest}" env.ui.info I18n.t("vagrant.provisioners.puppet.running_puppet") diff --git a/test/vagrant/provisioners/puppet_test.rb b/test/vagrant/provisioners/puppet_test.rb index 745e8b9fc..c7f6ddc86 100644 --- a/test/vagrant/provisioners/puppet_test.rb +++ b/test/vagrant/provisioners/puppet_test.rb @@ -29,7 +29,7 @@ class PuppetProvisionerTest < Test::Unit::TestCase end context "check manifest_dir" do - setup do + setup do @env.config.puppet.manifests_path = "manifests" end @@ -44,7 +44,7 @@ class PuppetProvisionerTest < Test::Unit::TestCase @action.check_manifest_dir end end - + context "share manifests folder" do setup do @manifests_path = "manifests" @@ -94,7 +94,7 @@ class PuppetProvisionerTest < Test::Unit::TestCase File.stubs(:exists?).with("#{@env.config.puppet.manifests_path}/#{@env.config.puppet.manifest_file}").returns(true) @action.set_manifest end - + should "raise an error if the manifest does not exist" do File.stubs(:exists?).with("#{@env.config.puppet.manifests_path}/#{@env.config.puppet.manifest_file}").returns(false) assert_raises(Vagrant::Provisioners::PuppetError) { @@ -114,12 +114,18 @@ class PuppetProvisionerTest < Test::Unit::TestCase @action.run_puppet_client end - should "cd into the pp_path directory and run puppet with given options" do + should "cd into the pp_path directory and run puppet with given options when given as an array" do @env.config.puppet.options = ["--modulepath", "modules", "--verbose"] @ssh.expects(:exec!).with("cd #{@env.config.puppet.pp_path} && sudo -E puppet --modulepath modules --verbose #{@manifest}").once @action.run_puppet_client end + should "cd into the pp_path directory and run puppet with the options when given as a string" do + @env.config.puppet.options = "--modulepath modules --verbose" + @ssh.expects(:exec!).with("cd #{@env.config.puppet.pp_path} && sudo -E puppet --modulepath modules --verbose #{@manifest}").once + @action.run_puppet_client + end + should "check the exit status if that is given" do @ssh.stubs(:exec!).yields(nil, :exit_status, :foo) @ssh.expects(:check_exit_status).with(:foo, anything).once