diff --git a/CHANGELOG.md b/CHANGELOG.md index a2e16723a..d9e25daa5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ ## 0.7.6 (unreleased) + - Run Chef commands in a single command. [GH-390] - Add `nfs` option for Chef to mount Chef folders via NFS. [GH-378] - Add translation for `aborted` state in VM. [GH-371] - Use full paths with the Chef provisioner so that restart cookbook will diff --git a/lib/vagrant/provisioners/chef_server.rb b/lib/vagrant/provisioners/chef_server.rb index 606ffaa7c..50e41a547 100644 --- a/lib/vagrant/provisioners/chef_server.rb +++ b/lib/vagrant/provisioners/chef_server.rb @@ -79,14 +79,13 @@ module Vagrant def run_chef_client command_env = config.binary_env ? "#{config.binary_env} " : "" - commands = ["cd #{config.provisioning_path}", - "#{command_env}#{chef_binary_path("chef-client")} -c client.rb -j dna.json"] + command = "#{command_env}#{chef_binary_path("chef-client")} -c #{config.provisioning_path}/client.rb -j #{config.provisioning_path}/dna.json" env.ui.info I18n.t("vagrant.provisioners.chef.running_client") vm.ssh.execute do |ssh| - ssh.sudo!(commands) do |channel, type, data| + ssh.sudo!(command) do |channel, type, data| if type == :exit_status - ssh.check_exit_status(data, commands) + ssh.check_exit_status(data, command) else env.ui.info("#{data}: #{type}") end diff --git a/lib/vagrant/provisioners/chef_solo.rb b/lib/vagrant/provisioners/chef_solo.rb index 54aa22bba..60f383ae7 100644 --- a/lib/vagrant/provisioners/chef_solo.rb +++ b/lib/vagrant/provisioners/chef_solo.rb @@ -73,14 +73,13 @@ module Vagrant def run_chef_solo command_env = config.binary_env ? "#{config.binary_env} " : "" - commands = ["cd #{config.provisioning_path}", - "#{command_env}#{chef_binary_path("chef-solo")} -c #{config.provisioning_path}/solo.rb -j #{config.provisioning_path}/dna.json"] + command = "#{command_env}#{chef_binary_path("chef-solo")} -c #{config.provisioning_path}/solo.rb -j #{config.provisioning_path}/dna.json" env.ui.info I18n.t("vagrant.provisioners.chef.running_solo") vm.ssh.execute do |ssh| - ssh.sudo!(commands) do |channel, type, data| + ssh.sudo!(command) do |channel, type, data| if type == :exit_status - ssh.check_exit_status(data, commands) + ssh.check_exit_status(data, command) else env.ui.info("#{data}: #{type}") end diff --git a/test/vagrant/provisioners/chef_server_test.rb b/test/vagrant/provisioners/chef_server_test.rb index 0c47b99d6..cafcb91b2 100644 --- a/test/vagrant/provisioners/chef_server_test.rb +++ b/test/vagrant/provisioners/chef_server_test.rb @@ -175,8 +175,8 @@ class ChefServerProvisionerTest < Test::Unit::TestCase @vm.ssh.stubs(:execute).yields(@ssh) end - should "cd into the provisioning directory and run chef client" do - @ssh.expects(:sudo!).with(["cd #{@config.provisioning_path}", "chef-client -c client.rb -j dna.json"]).once + should "run chef client" do + @ssh.expects(:sudo!).with("chef-client -c #{@config.provisioning_path}/client.rb -j #{@config.provisioning_path}/dna.json").once @action.run_chef_client end diff --git a/test/vagrant/provisioners/chef_solo_test.rb b/test/vagrant/provisioners/chef_solo_test.rb index dcf532f30..9995a34a4 100644 --- a/test/vagrant/provisioners/chef_solo_test.rb +++ b/test/vagrant/provisioners/chef_solo_test.rb @@ -249,8 +249,8 @@ class ChefSoloProvisionerTest < Test::Unit::TestCase @vm.ssh.stubs(:execute).yields(@ssh) end - should "cd into the provisioning directory and run chef solo" do - @ssh.expects(:sudo!).with(["cd #{@config.provisioning_path}", "chef-solo -c #{@config.provisioning_path}/solo.rb -j #{@config.provisioning_path}/dna.json"]).once + should "run chef solo" do + @ssh.expects(:sudo!).with("chef-solo -c #{@config.provisioning_path}/solo.rb -j #{@config.provisioning_path}/dna.json").once @action.run_chef_solo end