I want to edit ec2 node\'s node_data using a knife node
command.
I can manually do it by using below command.
knife node edit NODE_NAME
I have added a knife plugin to add to node_data.
require 'chef/knife'
require 'chef/knife/core/node_presenter'
class Chef
class Knife
class NodeJson_dataUpdate < Knife
deps do
require 'chef/node'
require 'json'
end
banner "knife node json_data update [NODE] [JSON_NODE_DATA]"
def run
node = Chef::Node.load(@name_args[0])
node_data = @name_args[1]
update_node_data(node, node_data)
node.save
output(node.normal.node_data)
end
def update_node_data(node,node_data)
parsed_node_data = JSON.parse(node_data)
parsed_node_data.each do |key,val|
if key.empty?
print "ERROR: Key is empty for value- "+val+". Not adding this to node_data.\n"
else
node.normal.node_data[key]=val
end
end
end
end
end
end