From a8ebd30cb90a83a5bafe1ea55c84512ffc4b6043 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Thu, 29 Aug 2013 11:26:21 -0700 Subject: [PATCH] provisioners/chef: use Subprocess to execute knife --- plugins/provisioners/chef/provisioner/chef_client.rb | 12 +++++++++++- templates/locales/en.yml | 8 ++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/plugins/provisioners/chef/provisioner/chef_client.rb b/plugins/provisioners/chef/provisioner/chef_client.rb index 0b9e2af65..565d08a95 100644 --- a/plugins/provisioners/chef/provisioner/chef_client.rb +++ b/plugins/provisioners/chef/provisioner/chef_client.rb @@ -1,4 +1,5 @@ require 'pathname' +require 'vagrant/util/subprocess' require File.expand_path("../base", __FILE__) @@ -108,7 +109,16 @@ module VagrantPlugins env[:ui].info(I18n.t( "vagrant.provisioners.chef.deleting_from_server", deletable: deletable, name: node_name)) - Kernel.system("knife #{deletable} delete --yes #{node_name} > /dev/null 2>&1") + + command = ["knife", deletable, "delete", "--yes", node_name] + r = Vagrant::Util::Subprocess.execute(*command) + if r.exit_code != 0 + env[:ui].error(I18n.t( + "vagrant.chef_client_cleanup_failed", + deletable: deletable, + stdout: r.stdout, + stderr: r.stderr)) + end end end end diff --git a/templates/locales/en.yml b/templates/locales/en.yml index fe9acae77..b00792ae6 100644 --- a/templates/locales/en.yml +++ b/templates/locales/en.yml @@ -25,6 +25,14 @@ en: CFEngine running in "single run" mode. Will execute one file. cfengine_single_run_execute: |- Executing run file for CFEngine... + chef_client_cleanup_failed: |- + Cleaning up the '%{deletable}' for Chef failed. The stdout and + stderr are shown below. Vagrant will continue destroying the machine, + so please clean up these resources manually. + + stdout: %{stdout} + + stderr: %{stderr} chef_run_list_empty: |- Warning: Chef solo run list is empty. This may not be what you want. provisioner_cleanup: |-