Skip to content

Instantly share code, notes, and snippets.

@c10l
Created December 6, 2012 11:57
Show Gist options
  • Save c10l/4223941 to your computer and use it in GitHub Desktop.
Save c10l/4223941 to your computer and use it in GitHub Desktop.
Vagrant delete Chef node and Client on destroy
module Vagrant
module Provisioners
class ChefClient
def cleanup
env[:ui].info "Attempting to remove client #{env[:vm].config.vm.host_name}"
`knife client show #{env[:vm].config.vm.host_name}`
if $?.to_i == 0
env[:ui].info "Removing client #{env[:vm].config.vm.host_name}"
`knife client delete #{env[:vm].config.vm.host_name} -y`
end
env[:ui].info "Attempting to remove node #{env[:vm].config.vm.host_name}"
`knife node show #{env[:vm].config.vm.host_name}`
if $?.to_i == 0
env[:ui].info "Removing node #{env[:vm].config.vm.host_name}"
`knife node delete #{env[:vm].config.vm.host_name} -y`
end
end
end
end
end
@FractalizeR
Copy link

What if Vagrant is configured to take node name from somewhere? Mine is configured like this:

NODE_FILE = "./chef.node"

I think in this case this snippet will not work. Also it gives an error:

rubygems_integration.rb:252:in block in replace_gem': chef is not part of the bundle. Add it to Gemfile.`

@lukas0krupa
Copy link

@FractalizeR I was having similar issue, I read most of conversations and no luck with any workaround provided. You may got here as well (hashicorp/vagrant#2476)

Then I tried similar thing, I removed/uninstall vagrant and install it again. However, I got another error, which sounds better:

stderr: WARNING: No knife configuration file found ERROR: Your private key could not be loaded from /etc/chef/client.pem

It might help.

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