Skip to content

Instantly share code, notes, and snippets.

@xdissent
Created December 8, 2010 05:25
Show Gist options
  • Save xdissent/732929 to your computer and use it in GitHub Desktop.
Save xdissent/732929 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)
`knife client show #{env["config"].chef.node_name}`
if $?.to_i == 0
env.ui.info "Removing client #{env["config"].chef.node_name}"
`knife client delete #{env["config"].chef.node_name} -y`
end
`knife node show #{env["config"].chef.node_name}`
if $?.to_i == 0
env.ui.info "Removing node #{env["config"].chef.node_name}"
`knife node delete #{env["config"].chef.node_name} -y`
end
@app.call(env)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment