Skip to content

Instantly share code, notes, and snippets.

@epcim
Forked from kam1kaze/reclass_tree.rb
Last active May 26, 2017 12:31
Show Gist options
  • Save epcim/1c245f8929e3312b6ccc615f3d936fa7 to your computer and use it in GitHub Desktop.
Save epcim/1c245f8929e3312b6ccc615f3d936fa7 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])
@epcim
Copy link
Author

epcim commented May 26, 2017

TODO:

  • fix hardcoded '/srv/salt/reclass' (best to replace to '.')
  • the servicess directory might be missing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment