diff --git a/lib/vagrant/provisioners/chef.rb b/lib/vagrant/provisioners/chef.rb index f554fd98a..e3be29492 100644 --- a/lib/vagrant/provisioners/chef.rb +++ b/lib/vagrant/provisioners/chef.rb @@ -75,6 +75,14 @@ module Vagrant raise Actions::ActionException.new(:chef_base_invalid_provisioner) end + def verify_binary(binary) + vm.ssh.execute do |ssh| + # Checks for the existence of chef binary and error if it + # doesn't exist. + ssh.exec!("which #{binary}", :error_key => :chef_not_detected, :error_data => {:binary => binary}) + end + end + def chown_provisioning_folder logger.info "Setting permissions on chef provisioning folder..." vm.ssh.execute do |ssh| diff --git a/lib/vagrant/provisioners/chef_server.rb b/lib/vagrant/provisioners/chef_server.rb index 6371f8825..2eba7e3d6 100644 --- a/lib/vagrant/provisioners/chef_server.rb +++ b/lib/vagrant/provisioners/chef_server.rb @@ -16,6 +16,7 @@ module Vagrant end def provision! + verify_binary("chef-client") chown_provisioning_folder create_client_key_folder upload_validation_key diff --git a/lib/vagrant/provisioners/chef_solo.rb b/lib/vagrant/provisioners/chef_solo.rb index 424c13222..825e327de 100644 --- a/lib/vagrant/provisioners/chef_solo.rb +++ b/lib/vagrant/provisioners/chef_solo.rb @@ -8,6 +8,7 @@ module Vagrant end def provision! + verify_binary("chef-solo") chown_provisioning_folder setup_json setup_solo_config diff --git a/templates/strings.yml b/templates/strings.yml index ac931a9dd..b35629278 100644 --- a/templates/strings.yml +++ b/templates/strings.yml @@ -78,6 +78,11 @@ The validation key set for `config.chef.validation_key_path` does not exist! This file needs to exist so it can be uploaded to the virtual machine. It is currently set to "<%= Vagrant.config.chef.validation_key_path %>" +:chef_not_detected: |- + The `<%= binary %>` binary appears to not be in the PATH of the guest. This + could be because the PATH is not properly setup or perhaps chef is not + installed on this guest. Chef provisioning can not continue without + chef properly installed. :command_box_invalid: |- Please specify a valid action to take on the boxes, either `add` or `remove`. Examples: diff --git a/test/vagrant/provisioners/chef_server_test.rb b/test/vagrant/provisioners/chef_server_test.rb index 91132f4e8..026979c28 100644 --- a/test/vagrant/provisioners/chef_server_test.rb +++ b/test/vagrant/provisioners/chef_server_test.rb @@ -10,6 +10,7 @@ class ChefServerProvisionerTest < Test::Unit::TestCase context "provisioning" do should "run the proper sequence of methods in order" do prov_seq = sequence("prov_seq") + @action.expects(:verify_binary).with("chef-client").once.in_sequence(prov_seq) @action.expects(:chown_provisioning_folder).once.in_sequence(prov_seq) @action.expects(:create_client_key_folder).once.in_sequence(prov_seq) @action.expects(:upload_validation_key).once.in_sequence(prov_seq) diff --git a/test/vagrant/provisioners/chef_solo_test.rb b/test/vagrant/provisioners/chef_solo_test.rb index c2e1dfb52..ce33a3f09 100644 --- a/test/vagrant/provisioners/chef_solo_test.rb +++ b/test/vagrant/provisioners/chef_solo_test.rb @@ -22,6 +22,7 @@ class ChefSoloProvisionerTest < Test::Unit::TestCase context "provisioning" do should "run the proper sequence of methods in order" do prov_seq = sequence("prov_seq") + @action.expects(:verify_binary).with("chef-solo").once.in_sequence(prov_seq) @action.expects(:chown_provisioning_folder).once.in_sequence(prov_seq) @action.expects(:setup_json).once.in_sequence(prov_seq) @action.expects(:setup_solo_config).once.in_sequence(prov_seq) @@ -29,7 +30,6 @@ class ChefSoloProvisionerTest < Test::Unit::TestCase @action.provision! end end - context "sharing cookbook folders" do setup do @host_cookbook_paths = ["foo", "bar"] diff --git a/test/vagrant/provisioners/chef_test.rb b/test/vagrant/provisioners/chef_test.rb index d21fcd486..2b6d9af28 100644 --- a/test/vagrant/provisioners/chef_test.rb +++ b/test/vagrant/provisioners/chef_test.rb @@ -62,6 +62,18 @@ class ChefProvisionerTest < Test::Unit::TestCase end end + context "verifying binary" do + setup do + @ssh = mock("ssh") + @vm.ssh.stubs(:execute).yields(@ssh) + end + + should "verify binary exists" do + binary = "foo" + @ssh.expects(:exec!).with("which #{binary}", :error_key => :chef_not_detected, :error_data => { :binary => binary }).once + @action.verify_binary(binary) + end + end context "permissions on provisioning folder" do should "create and chown the folder to the ssh user" do ssh_seq = sequence("ssh_seq")