tortuga
tortuga

Reputation: 757

Chef server REST API

wI'm exploring the Rest api of Chef for project purposes. I'm able to get, post and delete node/node-data. But I'm not able to execute PUT request, i.e. update the node related data on the server. Here is the screen shot of the error i get.enter image description here

Following is the code that is making the request. I have specified the authentication parameters properly, and they are working properly.

rest = Chef::REST.new(server_url, client_name, signing_key_filename)
print "Enter the node you want to edit :\n"
editnode = gets.chomp
node = rest.get_rest("/nodes/#{editnode}")
print "#{node.name}\n"
print "\t#{node.run_list}\n"
print "Now updating the node as per the parameters specified :\n"
update_node = {
"run_list" => "recipe[123]"
}
rest.put_rest("nodes/#{editnode}","update_node")    

Please suggest some solution.

Upvotes: 1

Views: 1496

Answers (1)

coderanger
coderanger

Reputation: 54211

So two issues:

  1. The main problem is that you quoted "update_node" in the put_rest so you are sending that back as a literal, when the server expects a hash.
  2. You can't just send the run list for the PUT, you need to send a full node data structure. The easiest way to do this is to modify the one you get back from the server from the GET.

Upvotes: 3

Related Questions