Created
October 30, 2016 08:57
-
-
Save ripienaar/097aa19b928ffffa57b4b7a4ec861fa4 to your computer and use it in GitHub Desktop.
This file contains 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
--- | |
one::services::enabled: true | |
one::two::abc: 8.45 | |
one::two::three: this is the string | |
puppet4::ca_server: otherhostname | |
puppet4::server: hostname |
This file contains 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
% ./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 |
This file contains 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
#!/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