Skip to content

Instantly share code, notes, and snippets.

@pikesley
Last active August 29, 2015 14:04
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 pikesley/60bc5bc6f376edb158c4 to your computer and use it in GitHub Desktop.
Save pikesley/60bc5bc6f376edb158c4 to your computer and use it in GitHub Desktop.
Convert .kitchen.yml to attributes for wrapper cookbook
#!/usr/bin/env ruby
require 'yaml'
y = YAML.load File.open ARGV[0]
def walk hash, stack = [], output = []
hash.each do |key, val|
stack << key
if val.is_a?(Hash)
walk val, stack, output
else
if not val.is_a?(Array)
val = "'%s'" % val
end
output << "default['%s'] = %s\n" % [ stack.join("']['"), val ]
stack.pop
end
end
stack.pop
output.sort
end
puts walk y['suites'][0]['attributes']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment