-
-
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
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
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) |
@franklouwers; perfect! thanks
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
WHOA. world rocked. Had totally forgotten this once i actually started using the chef_client provisioner
thanks guys