Skip to content

Instantly share code, notes, and snippets.

@danielsdeleo
Created May 22, 2012 19:45
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danielsdeleo/2771181 to your computer and use it in GitHub Desktop.
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.
# (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