-
-
Save Farzy/398374 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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