Created
May 22, 2012 19:45
-
-
Save danielsdeleo/2771181 to your computer and use it in GitHub Desktop.
Print a list of resources with the attributes filled in from node attrs, search, etc.
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
# (sudo) knife exec -c /etc/chef/client.rb resource_display.rb [FILTER] | |
# This will update the recipes and such on your machine, but it shouldn't make any real changes. | |
# Coded in 10 minutes, use at your own risk. | |
require 'chef/client' | |
require 'chef/checksum_cache' | |
require 'chef/provider' | |
require 'chef/providers' | |
require 'chef/resource' | |
require 'chef/resources' | |
Chef::Config[:solo] = false | |
class Chef | |
class Resource | |
def run_action(*args) | |
end | |
end | |
end | |
clean_argv = ARGV.select {|arg| arg !~ /^\-/ } | |
argv_index = clean_argv.index(::File.basename(__FILE__)) | |
filter = clean_argv[argv_index + 1] | |
#puts clean_argv.inspect | |
#puts "this = #{argv_index}" | |
#puts "next = #{clean_argv[argv_index + 1].inspect}" | |
#exit | |
controller = ::Chef::Client.new | |
controller.rest = api | |
controller.run_ohai | |
controller.build_node | |
controller.run_status.start_clock | |
controller.run_started | |
run_context = controller.setup_run_context | |
resources_to_display = run_context.resource_collection.all_resources | |
if filter | |
resources_to_display = resources_to_display.select { |r| r.to_s =~ /#{filter}/ } | |
puts "#{resources_to_display.size} matching filter #{filter}" | |
else | |
puts "Showing all resources (#{resources_to_display.size} total)" | |
end | |
resources_to_display.each {|r| puts r.to_text; puts "\n" } | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment