Skip to content

Instantly share code, notes, and snippets.

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
def call(env)
env["config"].vm.provisioners.each do |provisioner| "Attempting to remove client #{provisioner.config.node_name}"
`knife client show #{provisioner.config.node_name}`
if $?.to_i == 0 "Removing client #{provisioner.config.node_name}"
`knife client delete #{provisioner.config.node_name} -y`
end "Attempting to remove node #{provisioner.config.node_name}"
`knife node show #{provisioner.config.node_name}`
if $?.to_i == 0 "Removing node #{provisioner.config.node_name}"
`knife node delete #{provisioner.config.node_name} -y`
Copy link

patcon commented Dec 16, 2011

WHOA. world rocked. Had totally forgotten this once i actually started using the chef_client provisioner

thanks guys

Copy link

skippy commented Dec 16, 2011

@franklouwers; perfect! thanks

Copy link

c10l commented Dec 6, 2012

I adapted both cited works here and came to this:

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