diff --git a/lib/vagrant/provisioners/chef.rb b/lib/vagrant/provisioners/chef.rb index 7ba763337..6e2856c08 100644 --- a/lib/vagrant/provisioners/chef.rb +++ b/lib/vagrant/provisioners/chef.rb @@ -57,10 +57,10 @@ module Vagrant env.ui.info I18n.t("vagrant.provisioners.chef.json") # Set up initial configuration - data = { - :config => env.config.to_hash, - :directory => env.config.vm.shared_folders["v-root"][:guestpath], - } + data, default_share = { :config => env.config.to_hash }, env.config.vm.shared_folders["v-root"] + + # Add the directory on the guest if the default shared folder exists + data[:directory] = default_share[:guestpath] if default_share # And wrap it under the "vagrant" namespace data = { :vagrant => data } diff --git a/test/unit/vagrant/provisioners/chef_test.rb b/test/unit/vagrant/provisioners/chef_test.rb index c629fb5c8..b54cbdb20 100644 --- a/test/unit/vagrant/provisioners/chef_test.rb +++ b/test/unit/vagrant/provisioners/chef_test.rb @@ -186,6 +186,13 @@ class ChefProvisionerTest < Test::Unit::TestCase end end + should "not add the directory if the 'v-root' shared folder doesn't exist" do + @env.config.vm.shared_folders.delete("v-root") + assert_json do |data| + assert !data["vagrant"].has_key?("directory") + end + end + should "add the config to the JSON" do assert_json do |data| assert_equal @env.config.ssh.username, data["vagrant"]["config"]["ssh"]["username"]