Skip to content

Instantly share code, notes, and snippets.

@needle-deploy
Created November 26, 2012 19:55
Show Gist options
  • Save needle-deploy/4150249 to your computer and use it in GitHub Desktop.
Save needle-deploy/4150249 to your computer and use it in GitHub Desktop.
delete matching chef client and node when destroying a vagrant box
module Vagrant
module Provisioners
class ChefClient < Chef
def cleanup
::Chef::Config.from_file(File.expand_path('~/chef/repo/.chef/knife.rb'))
node_name = env[:vm].config.vm.provisioners[0].config.node_name
begin
puts "Destroying node #{node_name} on Chef server"
dead_node = ::Chef::Node.load(node_name)
dead_node.destroy
rescue => e
puts "Failed to destroy node #{node_name}: " + e.inspect
end
begin
puts "Destroying client #{node_name} on Chef server"
dead_client = ::Chef::ApiClient.load(node_name)
dead_client.destroy
rescue => e
puts "Failed to destroy client #{node_name}: " + e.inspect
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment