Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Chef: Delete node with knife and add it again later

Tags:

chef-infra

Say do a knife node delete 'NODENAME' to delete the node from chef server while leaving the corresponding VM running like it is.

Is it possible, if I need to make changes to that server in the future, to add the VM again as a node and run chef-client on it (or any other chef command for that matter)?

like image 702
j7nn7k Avatar asked Aug 28 '13 08:08

j7nn7k


2 Answers

Our use case involves creating virtual machines and chef bootstrapping them (using the hostname as the chef node name). Nodes are often deleted and created over and over with the same name. When we destroy the virtual machine we run the two commands to clean up in Chef.

knife node delete --yes NODENAME
knife client delete --yes NODENAME

Keep in mind that in our use case we are not interested in keeping any information about what the node was doing (i.e., its run list or other attributes).

If you don't want to delete the server, you can run the above two commands to clean up the node from the chef server and then run the following commands on the machine to remove chef locally. Once done you can chef bootstrap the machine again.

#depending on how you installed chef
yum -y remove chef 
OR 
rpm -e `rpm -q chef`  # rpm -q chef returns the version of chef installed

rm -rf /var/chef
rm -rf /etc/chef
rm -rf /opt/chef
like image 79
Tom Weiss Avatar answered Nov 03 '22 01:11

Tom Weiss


I think, after delete the node from your chef server the credentials of the machines which you delete was gone from the server. Again if you want to add the same node again then you must delete the client.pem (/etc/chef/client.pem) file in that node which was created by the previous bootstrap.

like image 24
VijayVishnu Avatar answered Nov 03 '22 00:11

VijayVishnu