Last active
August 29, 2015 14:14
-
-
Save sczizzo/c24b1a7bb76e770c5e95 to your computer and use it in GitHub Desktop.
Cookbook Versions Report Handler
This file contains hidden or 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
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