Skip to content

Instantly share code, notes, and snippets.

@octplane
Created May 4, 2010 15:56
Show Gist options
  • Save octplane/389574 to your computer and use it in GitHub Desktop.
Save octplane/389574 to your computer and use it in GitHub Desktop.
cooto.rb
#!/usr/bin/env ruby
# Use dot separated pathspec:
# ./cooto.rb mysql.datadir
# /var/lib/mysql
require 'rubygems'
require 'chef/client'
require 'ohai'
Chef::Config.from_file("/etc/chef/client.rb")
Chef::Log.level :info
ohai = Ohai::System.new()
ohai.all_plugins
node_name ||= ohai[:fqdn] ? ohai[:fqdn] : ohai[:hostname]
Chef::Config[:node_name] = node_name
c = Chef::Client.new()
c.build_node
current_node = c.node
current_path = []
ARGV[0].split(".").each do |k|
if current_node.has_key?(k)
current_path << k
current_node = current_node[k]
else
puts "Missing key #{k} in #{current_path.join(".")}. Available keys are:"
puts current_node.keys.sort.join("\n")
exit(-1)
end
end
current_node.each do |k,v|
if k==nil && v!=nil
puts v
elsif k!=nil && v==nil
puts k
elsif k!=nil && v!=nil
puts "#{k}\t#{v}"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment