Skip to content

Instantly share code, notes, and snippets.

@sczizzo
Last active August 29, 2015 14:14
Show Gist options
  • Save sczizzo/c24b1a7bb76e770c5e95 to your computer and use it in GitHub Desktop.
Save sczizzo/c24b1a7bb76e770c5e95 to your computer and use it in GitHub Desktop.
Cookbook Versions Report Handler
require 'chef/handler'
require 'chef/log'
require 'json'
# Based on https://docs.chef.io/handlers.html#cookbook-versions
module Handlers
class CookbookVersions < Chef::Handler
def report
cookbooks = run_context.cookbook_collection
versions = cookbooks.keys.inject({}) do |h, k|
cb = cookbooks[k]
h[cb.name.to_s] = cb.version.to_s
h
end
node.automatic['cookbooks'] = versions
node.save
Chef::Log.debug 'Cookbook versions: %s' % JSON.pretty_generate(node['cookbooks'])
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment