How to output pretty json in puppet

How to output pretty json in puppet

Published on 2012/03/14 11:12:001 min read

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).


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


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

I found configdata.tojson wasn't going to work for me because it seemed to output things in different orders each run.

(it was 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.

Edit: After much trial and error, I ended writing my own library.

Gavin Mogan
Burnaby, BC, Canada

I'm a software developer at the awesome Sauce Labs. I do a bunch of other random open source development. I also play games, both board and video games and love to read. You can usually find me on various services as halkeye.



Git+push notification with Gitolite and Jenkins


Busy Week here