Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Chef Infrastructure Automation Cookbook Second Edition

You're reading from   Chef Infrastructure Automation Cookbook Second Edition Over 80 recipes to automate your cloud and server infrastructure with Chef and its associated toolset

Arrow left icon
Product type Paperback
Published in May 2015
Publisher
ISBN-13 9781785287947
Length 278 pages
Edition 1st Edition
Tools
Arrow right icon
Author (1):
Arrow left icon
Matthias Marschall Matthias Marschall
Author Profile Icon Matthias Marschall
Matthias Marschall
Arrow right icon
View More author details
Toc

Table of Contents (9) Chapters Close

Preface 1. Chef Infrastructure FREE CHAPTER 2. Evaluating and Troubleshooting Cookbooks and Chef Runs 3. Chef Language and Style 4. Writing Better Cookbooks 5. Working with Files and Packages 6. Users and Applications 7. Servers and Cloud Infrastructure Index

Deleting a node from the Chef server

Bootstrapping a node not only installs Chef on that node, but creates a client object on the Chef server as well. Running the Chef client on your node uses the client object to authenticate itself against the Chef server on each run.

Additionally, to registering 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.

Getting ready

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

How to do it...

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

  1. Delete the node object:
    mma@laptop:~/chef-repo $ knife node delete my_node
    
    Do you really want to delete my_node? (Y/N) y
    Deleted node[my_node]
  2. Delete the client object:
    mma@laptop:~/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.

There's more...

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

  1. Run the chef command-line tool to install the knife plugin:
    mma@laptop:~/chef-repo $ chef gem install knife-playground
    
    ...TRUNCATED OUTPUT...
    Installing knife-playground (0.2.2)
  2. Run the knife pg clientnode delete subcommand:
    mma@laptop:~/chef-repo $ knife pg clientnode delete my_node
    
    Deleting CLIENT my_node...
    Do you really want to delete my_node? (Y/N) y
    Deleted client[my_node]
    Deleting NODE my_node...
    Do you really want to delete my_node? (Y/N) y
    Deleted node[my_node]

See also

  • Read about how to do this when using Vagrant in the Managing virtual machines with Vagrant recipe in this recipe
  • Read about how to set up your Chef server and register your nodes in the Using the hosted Chef platform recipe in this chapter
You have been reading a chapter from
Chef Infrastructure Automation Cookbook Second Edition
Published in: May 2015
Publisher:
ISBN-13: 9781785287947
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image