Skip to content

Instantly share code, notes, and snippets.

@tq-jappy
Created June 6, 2014 16:46
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 tq-jappy/a81e195aed23036d1217 to your computer and use it in GitHub Desktop.
Save tq-jappy/a81e195aed23036d1217 to your computer and use it in GitHub Desktop.
sample to print hostname list of chef nodes
require 'rubygems'
require 'chef/config'
require 'chef/log'
require 'chef/node'
require 'chef/rest'
chef_server_url = "https://chefserver/"
client_name = "admin"
signing_key_filename = "/root/.chef/admin.pem"
rest = Chef::REST.new(chef_server_url, client_name, signing_key_filename)
nodes = rest.get_rest("/nodes/")
nodes.keys.each do |node_name|
node = rest.get_rest("/nodes/#{node_name}/")
puts node["hostname"]
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment