Skip to content

Instantly share code, notes, and snippets.

@phoolish
Forked from gaffneyc/node_update_from_file.rb
Created July 16, 2013 14:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save phoolish/6009417 to your computer and use it in GitHub Desktop.
Save phoolish/6009417 to your computer and use it in GitHub Desktop.
class NodeUpdateFromFile < ::Chef::Knife
deps do
require "chef/node"
require "chef/json_compat"
require "chef/knife/core/object_loader"
end
banner "knife node update from file FILE (options)"
def loader
@loader ||= ::Chef::Knife::Core::ObjectLoader.new(Chef::Node, ui)
end
def run
update = loader.load_from("nodes", @name_args[0])
node = ::Chef::Node.load(update.name)
# Replace attributes, run_list, and chef_environment from the new node
# definition.
node.normal_attrs = update.normal_attrs
node.override_attrs = update.override_attrs
node.default_attrs = update.default_attrs
node.run_list.reset!(update.run_list)
node.chef_environment(update.chef_environment)
# Expand the run_list in case it has changed
node.expand!
node.save
output(format_for_display(node)) if config[:print_after]
ui.info("update Node #{update.name}!")
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment