Created
November 26, 2012 19:55
-
-
Save needle-deploy/4150249 to your computer and use it in GitHub Desktop.
delete matching chef client and node when destroying a vagrant box
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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