Monday, August 7, 2017

Deleting a node from the Chef Server

Every node managed by a Chef server has a corresponding client object on the Chef server.Running the Chef client on your node uses the client object to authenticate itself against the Chef server on each run.

Additionally,to register a client, a node object is created on the Chef server.The node object is the main data structure,which you can use to query node data inside your recipes.

Make sure you have at least one node registered on your Chef server that is safe to remove.

How to do it?

delete the node and client object to completely remove a node from the Chef server.

1)Delete the node object
local@workstation:~/chef-repo $ knife node delete my_node 
Do you really want to delete my_node? (Y/N) y
Dleted node[my_node]

2) Delete the client object:
local@workstation:~/chef-repo $  knife client delete my_node
Do you really want to delete my_node? (Y/N) y
Deleted client[my_node]

 How it works?

To keep your Chef server  clean,it's important to not only manage your node objects but to also take care of your  client objects,as well.

Knife connects to the Chef server and deletes the node object with a given name,using the Chef server  RESTful API.

The same happens while deleting the client object on the Chef server.

After deleting both objects,your node is totally removed from the Chef server.Now you can reuse the same node name with a new box or virtual machine.

Having to issue two commands is a bit tedious and error-prone.To simplify things,you can use a knife plugin called playground .

1)Run the chef command-line tool to install the knife plugin:

local@workstation:~/chef-repo $  chef gem install knife-playground
..TRUNCATED OUTPUT...
Installing knife-playground (0.2.2).

2) Run the knife pgclientnode delete subcommand:

local@workstation:~/chef-repo $  knife pgclientnode delete my_node 

Deleting CLIENT my_node....

Do you really want to delete my_node? (Y/N) y
Delete client[my_node]
Deleted node[my_node]

















 

No comments:

Post a Comment