How to output pretty json in puppet

Mar 14, 2012 11:12

Originally published at http://www.halkeye.net/2012/03/14/output-pretty-json-puppet/. You can comment here or http://www.halkeye.net/2012/03/14/output-pretty-json-puppet/#comments.
It kept seeming like it should be straight forward. Various attempts by myself (mostly because I don’t know ruby) seemed to fail. I’m just leaving it here now that I figured out how to get it working so I can find it again (and hopefully help others).

init.pp

$config_data = { "foo" => "bar" }

template.erb

<%= require "json"; JSON.pretty_generate config_data %>

I found config_data.to_json wasn’t going to work for me because it seemed to output things in different orders each run.

(it was http://snippets.aktagon.com/snippets/412-How-to-pretty-print-JSON-data-with-Ruby that helped me figure this out)

Edit: While pretty, still doesn’t sort so puppet can update the config file each run :( I will figure this out.

linux

Previous post Next post
Up