Skip to content

Commit

Permalink
Add unused_cookbooks script
Browse files Browse the repository at this point in the history
  • Loading branch information
stevendanna committed Nov 3, 2011
1 parent faebce2 commit 750f453
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions exec/unused_cookbooks.rb
@@ -0,0 +1,25 @@
# unused_cookbooks.rb: List cookboosk that are note used by any nodes.
#

# First, we get a list of all the cookbooks
all_cookbooks = api.get("cookbooks").keys

used_cookbooks = Array.new

# Next, we expand the run list of each node,
# and use the API to determine cookbook
# dependencies.
nodes.all do |n|
expanded_run_list = n.expand!('server').recipes
cookbook_hash = api.post("environments/#{n.chef_environment}/cookbook_versions",
{:run_list => expanded_run_list})
used_cookbooks += cookbook_hash.keys
end

# Remove duplicates
used_cookbooks.uniq!

# Diff the two lists
puts "Unused Cookbooks:"
puts all_cookbooks - used_cookbooks
exit 0

0 comments on commit 750f453

Please sign in to comment.