(Blogpost in English, to help googlers).
If you are using vagrant (and there are plenty of good reasons you should!) and use Opscode Chef to provision your vms, you have probably encountered the following problem. You vagrant up your testnode, have finished your testing, so you vagrant destroy it. A while later, you need to test something else, and vagrant up again, only to notice that your chef provisioning fails, because the client and the node of your test-vm were already registered on the chef server.
The following snippet (which you can just append to your Vagrantfile) will auto-deregister your vms on destroy:
module Vagrant
module Provisioners
class ChefClient < Chef
def cleanup
puts `sh -c 'knife client delete #{HOSTNAME} -y'`
puts `sh -c 'knife node delete #{HOSTNAME} -y'`
end
end
end
end
This assumes you have declared your HOSTNAME as a contant somewhere in your Vagrantfile.