Skip to content

Instantly share code, notes, and snippets.

@kam1kaze
Last active April 6, 2017 15:13
Show Gist options
  • Save kam1kaze/d70d7e759429ab26cdb43014aa99c94e to your computer and use it in GitHub Desktop.
Save kam1kaze/d70d7e759429ab26cdb43014aa99c94e to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'yaml'
def parse_yaml(cl, align = '')
puts align + cl
reclass_dir = '/srv/salt/reclass'
yaml_file = if cl =~ /\.yml$/
cl
elsif File.exist?(reclass_dir + '/classes/' + cl.tr('.', '/') + '/init.yml')
reclass_dir + '/classes/' + cl.tr('.', '/') + '/init.yml'
else
reclass_dir + '/classes/' + cl.tr('.', '/') + '.yml'
end
data = YAML.load_file(yaml_file)
if data.key?('classes')
align = align + ' '
data['classes'].each do |nested_class|
parse_yaml(nested_class, align = align)
end
end
end
parse_yaml(ARGV[0])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment