anatoly techtonik
anatoly techtonik

Reputation: 20531

Can Chef detect unused Cookbooks?

Can Chef detect if some Cookbooks in my repository are unused?

Can it detect unused Cookbooks just for a single recipe?

Upvotes: 5

Views: 1588

Answers (2)

Oleksandr Pryimak
Oleksandr Pryimak

Reputation: 1581

I used

ls /var/cache/chef/cookbooks

to find out the list of all cached cookbooks. This list is the list of all cookbooks the chef-client used the last time. Note that chef client removes unused cookbooks from the cache.

Upvotes: 2

Tim Potter
Tim Potter

Reputation: 2457

Chef can't really tell by itself, but you can use knife search node to gather up the expanded run list (stored in the "recipes" attribute) for each node then use regular Unix tools to clean it up. This will give you a list of cookbook used. Compare this with what's in your repo to determine unused cookbooks

$ knife search node '*:*' -a recipes | \
    grep "^ " | sort | uniq | tr -d ' '
apache2
apt
chef-client
chef-client::config
chef-client::delete_validation
...

Filter out every line with "::" to remove recipe and leave just cookbooks.

Upvotes: 6

Related Questions