Permalink
Browse files

Add `node required cookbooks` plugins.

This plugin prints the list of cookbooks required for the given node
to complete its chef-client run.
  • Loading branch information...
1 parent 8d06b0e commit c914e3bc070a2a6416e50dfd9b8ee6635b37cea0 @stevendanna committed Oct 24, 2013
Showing with 26 additions and 0 deletions.
  1. +26 −0 plugins/node_required_cookbooks.rb
View
26 plugins/node_required_cookbooks.rb
@@ -0,0 +1,26 @@
+class NodeRequiredCookbooks < Chef::Knife
+ banner "knife node required cookbooks NODE_NAME"
+
+ def run
+ node_name = @name_args[0]
+
+ if !node_name
+ show_usage
+ ui.fatal "You must specify a node name."
+ exit 1
+ end
+
+ node = Chef::Node.load(node_name)
+
+ # Expand node run_list
+ run_list_expansion = node.run_list.expand(node.chef_environment)
+ run_list = run_list_expansion.recipes.with_version_constraints_strings
+
+ metadata = rest.post_rest("environments/#{node.chef_environment}/cookbook_versions",
+ :run_list => run_list)
+
+ metadata.each do |name, ckbk|
+ ui.output("#{name} #{ckbk.version}")
+ end
+ end
+end

0 comments on commit c914e3b

Please sign in to comment.