Created
June 11, 2013 18:31
-
-
Save double-z/5759452 to your computer and use it in GitHub Desktop.
chef-walk-resource-collection.rb
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
# TODO throwing error: | |
# Cannot find a resource for to_ary on ubuntu version 12.04 | |
require 'set' | |
file "/root/chef_resources-#{node.name}.json" do | |
resource_clxn = Chef::ResourceCollection.new | |
run_context.resource_collection.each do |r| | |
next if r.class.to_s == 'Chef::Resource::NodeMetadata' | |
r = r.dup | |
r.instance_eval do | |
content('') if respond_to?(:content) | |
variables({}) if respond_to?(:variables) | |
remove_instance_variable('@options') rescue nil | |
params.delete(:options) if respond_to?(:params) | |
# if respond_to?(:options) | |
# begin ; options({}) ; rescue options('') ; end | |
# end | |
@delayed_notifications = [] | |
@immediate_notifications = [] | |
end | |
resource_clxn << r | |
end | |
content resource_clxn.to_json(JSON::PRETTY_STATE_PROTOTYPE)+"\n" | |
action :create | |
owner 'root' | |
group 'root' | |
mode "0600" # only readable by root | |
end | |
def walk_resource_path | |
Chef::Log.info('Resources Used In Order') | |
run_context.resource_collection.each do |resource| | |
# puts "resource start" | |
puts resource.class.name | |
# puts resource.instance_variables.inspect | |
# Chef::Log.info(resource.instance_variables.inspect) | |
# puts "resource stop" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment