Skip to content

Instantly share code, notes, and snippets.

@jflowers
Forked from needle-deploy/gist:4150249
Last active December 9, 2015 19:38
Show Gist options
  • Save jflowers/4317671 to your computer and use it in GitHub Desktop.
Save jflowers/4317671 to your computer and use it in GitHub Desktop.
Old Vagrant destroy Chef client on vagrant destroy
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