Skip to content

Instantly share code, notes, and snippets.

@skippy
Forked from xdissent/middleware.rb
Created June 6, 2011 17:19
  • Star 9 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save skippy/1010660 to your computer and use it in GitHub Desktop.
delete vagrant vm's chef client and node from chef server on destroy
class OnDestroyMiddleware
def initialize(app, env)
@app = app
end
def call(env)
env["config"].vm.provisioners.each do |provisioner|
env.ui.info "Attempting to remove client #{provisioner.config.node_name}"
`knife client show #{provisioner.config.node_name}`
if $?.to_i == 0
env.ui.info "Removing client #{provisioner.config.node_name}"
`knife client delete #{provisioner.config.node_name} -y`
end
env.ui.info "Attempting to remove node #{provisioner.config.node_name}"
`knife node show #{provisioner.config.node_name}`
if $?.to_i == 0
env.ui.info "Removing node #{provisioner.config.node_name}"
`knife node delete #{provisioner.config.node_name} -y`
end
end
@app.call(env)
end
end
Vagrant::Action[:destroy].use(OnDestroyMiddleware)
@c10l
Copy link

c10l commented Dec 6, 2012

I adapted both cited works here and came to this: https://gist.github.com/4223941

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment