-
-
Save millisami/3731707 to your computer and use it in GitHub Desktop.
set an attribute on the node
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
# Knife plugin to set an attribute on the node | |
# Usage: | |
# $knife node exec [nodename] 'node.set[:somevalue] = true' | |
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