Skip to content

Instantly share code, notes, and snippets.

@mhorbul
Created September 15, 2012 05:12
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mhorbul/3726422 to your computer and use it in GitHub Desktop.
Save mhorbul/3726422 to your computer and use it in GitHub Desktop.
class NodeExec < Chef::Knife
banner "knife node exec NODE CODE (options)"
deps do
require 'chef/search/query'
end
def run
if name_args.size == 2
node_name = name_args.first
code = name_args.last
else
ui.fatal "Please provide a node name & code"
exit 1
end
q = Chef::Search::Query.new
q.search('node', "name:#{node_name}") do |node|
if node.run_list.empty?
ui.warn("#{node.name}'s run list is empty.")
exit 1
end
ui.msg("The following piece of code will be executed against node #{node_name}:")
ui.output(code)
ui.confirm("Are you sure?")
ui.output eval(code)
node.save
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment