Chef cleanup - nodes, environments, cookbooks, roles etc.,

3.4k views Asked by At

I recently inherited a chef environment that has quite some stale nodes and environments and lot of old cookbooks. For e.g. the AWS console shows that I have around 150 instances running, but a knife status shows 700 nodes.

Normally, I use ansible, so I understand how that works to a large extent. But Chef is not something I fully understand. I understand a few of the knife commands and can do basic tasks.

But things are complicated by the fact that most of the ec2 instances appear to have been created with different keys (is that a best practice?) and identifying dead nodes is further complicated.

Does chef store this information for each node i.e. what key a node was instantiated with and I can use the information to check the status of a node and perhaps automate the removal of a node?

Similarly, list environments that aren't used and delete and so on.

Is there an existing tool that I can use to clean up this chef environment? I've searched, but haven't found anything that fits the purpose. There is a tool to clean up cookbooks, but that's the least of my problems.

How would I go about cleaning this up, specifically the nodes and then any environments?

2

There are 2 answers

0
Tensibai On BEST ANSWER

See knife plugins here

knife-cleanup, knife-audit and knife-ohno could be of some help to create list of objects to be deleted.

0
Roland On

You can use knife to execute searches against the saved node data (including ohai): https://docs.chef.io/knife_search.html

Together with the aws cli you'll get anything you need to write a small shell script that executes knife node delete and knife client delete for nodes.

Once you have cleaned up all dead nodes, you can use the search to query for nodes in environments and delete environments without nodes.