Skip to content

Instantly share code, notes, and snippets.

@christopherwood
Forked from ripienaar/in.yaml
Created October 31, 2016 13:50
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 christopherwood/03e855d4fd67b19588357bb2e61694d0 to your computer and use it in GitHub Desktop.
Save christopherwood/03e855d4fd67b19588357bb2e61694d0 to your computer and use it in GitHub Desktop.
---
one::services::enabled: true
one::two::abc: 8.45
one::two::three: this is the string
puppet4::ca_server: otherhostname
puppet4::server: hostname
% ./make_pretty_yaml.rb test.yaml
---
one::two::three: this is the string
one::services::enabled: true
one::two::abc: 8.45
puppet4::ca_server: otherhostname
puppet4::server: hostname
#!/opt/puppetlabs/puppet/bin/ruby
require "yaml"
data = YAML.load_file(ARGV.shift)
class_order = [String, TrueClass, FalseClass, Fixnum, Float, Array, Hash]
puts "---"
last_module = nil
data.sort_by do |k, v|
[
k.split("::").first,
class_order.index(v.class)
]
end.each do |k, v|
mod_name = k.split("::").first
puts if last_module && mod_name != last_module
last_module = mod_name
puts YAML.dump(Hash[[[k, v]]]).split(/\n/)[1..-1].join("\n") + "\n"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment