Created
November 1, 2012 04:30
-
-
Save sawanoboly/3991745 to your computer and use it in GitHub Desktop.
Convert ohai output(json) to cookbook attributes format.
This file contains hidden or 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
def _out(k,hash) | |
hash.each_pair do |k2,v2| | |
str = [k,"['#{k2}']"].join | |
ha = {str => v2} | |
out ha | |
end | |
end | |
def out(hash) | |
hash.each_pair do |k,v| | |
if v.class == Hash | |
_out k,v | |
else | |
v = %("#{v.to_s}") unless v.class == Array | |
puts [k,v.to_s].join(" = ") | |
end | |
end | |
end | |
require 'json' | |
if STDIN.tty? | |
puts "Usage: Please input ohai json from stdin." | |
exit | |
end | |
json = JSON.parse(STDIN.read) | |
node = {:node => json} | |
out node |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
$ knife node show lxc -l -f json | ruby ./ohai_to_attributes.rb
node['name'] = "lxc"
node['chef_environment'] = "_default"
node['run_list'] = []
node['normal']['tags'] = []
node['automatic']['dmi']['chassis']['manufacturer'] = "Bochs"
-- sinp --