Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
faebce2
commit 750f453
Showing
1 changed file
with
25 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |