diff --git a/plugins/provisioners/chef/config/chef_client.rb b/plugins/provisioners/chef/config/chef_client.rb index ad0457593..595e4e5c7 100644 --- a/plugins/provisioners/chef/config/chef_client.rb +++ b/plugins/provisioners/chef/config/chef_client.rb @@ -6,6 +6,8 @@ module VagrantPlugins class ChefClient < Base attr_accessor :chef_server_url attr_accessor :client_key_path + attr_accessor :delete_client + attr_accessor :delete_node attr_accessor :encrypted_data_bag_secret_key_path attr_accessor :encrypted_data_bag_secret attr_accessor :environment @@ -17,6 +19,8 @@ module VagrantPlugins @chef_server_url = UNSET_VALUE @client_key_path = UNSET_VALUE + @delete_client = UNSET_VALUE + @delete_node = UNSET_VALUE @encrypted_data_bag_secret_key_path = UNSET_VALUE @encrypted_data_bag_secret = UNSET_VALUE @environment = UNSET_VALUE diff --git a/plugins/provisioners/chef/provisioner/chef_client.rb b/plugins/provisioners/chef/provisioner/chef_client.rb index 40b0618c2..e277814a3 100644 --- a/plugins/provisioners/chef/provisioner/chef_client.rb +++ b/plugins/provisioners/chef/provisioner/chef_client.rb @@ -97,6 +97,18 @@ module VagrantPlugins def guest_validation_key_path File.join(@config.provisioning_path, "validation.pem") end + + def cleanup + delete_from_chef_server('client') if config.delete_client + delete_from_chef_server('node') if config.delete_node + end + + def delete_from_chef_server(deletable) + node_name = (config.node_name || env[:vm].config.vm.host_name) + 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") + end end end end diff --git a/templates/locales/en.yml b/templates/locales/en.yml index b7b902f5a..514f8e2c7 100644 --- a/templates/locales/en.yml +++ b/templates/locales/en.yml @@ -1145,6 +1145,7 @@ en: server_validation_key_doesnt_exist: |- 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. + deleting_from_server: "Deleting %{deletable} \"%{name}\" from Chef server..." puppet: not_detected: |-