Skip to content

Instantly share code, notes, and snippets.

@acharlieh
Last active February 2, 2017 17:09
Show Gist options
  • Save acharlieh/ada96c900ec9e9d37c32455ff6070590 to your computer and use it in GitHub Desktop.
Save acharlieh/ada96c900ec9e9d37c32455ff6070590 to your computer and use it in GitHub Desktop.
Quick Script to pull versions of all cookbooks from a node
require 'json'
# Cookbooks from a folder (like when you do a berks vendor)
# json = Dir.glob('./*/metadata.json').collect do |file|
# Cookbooks from a node cache
json = Dir.glob('/var/chef/cache/cookbooks/*/metadata.json').collect do |file|
hash = JSON.parse(File.read(file))
{ hash['name'] => hash['version'] }
end.reduce({}, :merge).to_json
puts json
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment