diff --git a/CHANGELOG.md b/CHANGELOG.md index 8d139c20a..50b7003a5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,8 @@ - Get rid of RubyGems deprecations introduced with RubyGems 1.8.x - Search in pre-release gems for plugins as well as release gems. - Support for Chef-solo `data_bags_path` [GH-362] + - Can specify path to Chef binary using `binary_path` [GH-342] + - Can specify additional environment data for Chef using `binary_env` [GH-342] ## 0.7.4 (May 12, 2011) diff --git a/lib/vagrant/provisioners/chef.rb b/lib/vagrant/provisioners/chef.rb index 9c8336cb8..246c83891 100644 --- a/lib/vagrant/provisioners/chef.rb +++ b/lib/vagrant/provisioners/chef.rb @@ -16,6 +16,13 @@ module Vagrant end end + # Returns the path to the Chef binary, taking into account the + # `binary_path` configuration option. + def chef_binary_path(binary) + return binary if !config.binary_path + return File.join(config.binary_path, binary) + end + def chown_provisioning_folder vm.ssh.execute do |ssh| ssh.sudo!("mkdir -p #{config.provisioning_path}") diff --git a/lib/vagrant/provisioners/chef_server.rb b/lib/vagrant/provisioners/chef_server.rb index c3cf0828e..606ffaa7c 100644 --- a/lib/vagrant/provisioners/chef_server.rb +++ b/lib/vagrant/provisioners/chef_server.rb @@ -41,7 +41,7 @@ module Vagrant end def provision! - verify_binary(chef_client_binary) + verify_binary(chef_binary_path("chef-client")) chown_provisioning_folder create_client_key_folder upload_validation_key @@ -78,8 +78,9 @@ module Vagrant end def run_chef_client + command_env = config.binary_env ? "#{config.binary_env} " : "" commands = ["cd #{config.provisioning_path}", - "#{config.binary_env} #{chef_client_binary} -c client.rb -j dna.json"] + "#{command_env}#{chef_binary_path("chef-client")} -c client.rb -j dna.json"] env.ui.info I18n.t("vagrant.provisioners.chef.running_client") vm.ssh.execute do |ssh| @@ -93,14 +94,6 @@ module Vagrant end end - def chef_client_binary - if config.binary_path.nil? || config.binary_path.empty? - "chef-client" - else - File.join(config.binary_path, "chef-client") - end - end - def validation_key_path File.expand_path(config.validation_key_path, env.root_path) end diff --git a/lib/vagrant/provisioners/chef_solo.rb b/lib/vagrant/provisioners/chef_solo.rb index 6afdc831b..894858f65 100644 --- a/lib/vagrant/provisioners/chef_solo.rb +++ b/lib/vagrant/provisioners/chef_solo.rb @@ -33,7 +33,7 @@ module Vagrant end def provision! - verify_binary(chef_solo_binary) + verify_binary(chef_binary_path("chef-solo")) chown_provisioning_folder setup_json setup_solo_config @@ -70,7 +70,8 @@ module Vagrant end def run_chef_solo - commands = ["cd #{config.provisioning_path}", "#{config.binary_env} #{chef_solo_binary} -c solo.rb -j dna.json"] + command_env = config.binary_env ? "#{config.binary_env} " : "" + commands = ["cd #{config.provisioning_path}", "#{command_env}#{chef_binary_path("chef-solo")} -c solo.rb -j dna.json"] env.ui.info I18n.t("vagrant.provisioners.chef.running_solo") vm.ssh.execute do |ssh| @@ -84,14 +85,6 @@ module Vagrant end end - def chef_solo_binary - if config.binary_path.nil? || config.binary_path.empty? - "chef-solo" - else - File.join(config.binary_path, "chef-solo") - end - end - def host_folder_paths(paths) # Convert single cookbook paths such as "cookbooks" or [:vm, "cookbooks"] # into a proper array representation. diff --git a/test/vagrant/provisioners/chef_test.rb b/test/vagrant/provisioners/chef_test.rb index f2bdf822b..90b9a6fda 100644 --- a/test/vagrant/provisioners/chef_test.rb +++ b/test/vagrant/provisioners/chef_test.rb @@ -78,6 +78,18 @@ class ChefProvisionerTest < Test::Unit::TestCase end end + context "chef binary path" do + should "return just the binary if no binary path is set" do + @config.binary_path = nil + assert_equal "foo", @action.chef_binary_path("foo") + end + + should "return the joined binary path and binary if set" do + @config.binary_path = "/foo" + assert_equal File.join(@config.binary_path, "bar"), @action.chef_binary_path("bar") + end + end + context "permissions on provisioning folder" do should "create and chown the folder to the ssh user" do ssh_seq = sequence("ssh_seq")