Skip to content

Instantly share code, notes, and snippets.

@chef
Created January 29, 2009 15:38
Show Gist options
  • Save chef/54588 to your computer and use it in GitHub Desktop.
Save chef/54588 to your computer and use it in GitHub Desktop.
#!/usr/bin/ruby
require 'rubygems'
require 'chef'
require 'chef/node'
require 'chef/rest'
# A registration for your API access
api_user = "monkey"
# A password for the API access
api_pass = "pants"
# A validation token, if you use them
validation_token = nil
# The name of a node to look up - replace dots with _
node_name = "latte_local"
rest = Chef::REST.new(Chef::Config[:registration_url])
## Basically, all this tear up stuff should be replaced with
## two method calls when CHEF-66 gets closed.
# First, we're going to create a false registration for
# API access
rest.register(api_user, api_pass, validation_token)
# Then we authenticate
rest.authenticate(api_user, api_pass)
# Now you can do whatever you want, assuming you are validated
node = rest.get_rest("nodes/#{node_name}")
node[:signal] = "noise"
# Save it
rest.put_rest("nodes/#{node_name}", node)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment