Convert a hash into JSON in Puppet

This article shows you how to convert a hash into JSON in Puppet using a simple ERB template that gets its data from Hiera.
Suppose you have this data in Hiera:
myhash:
mykey:
foo: one
bar: two
Converting a hash into a JSON file on the target node is surprisingly easy. First look up the data:
$myhash = lookup('myhash', Hash)
Then create a simple ERB template (here: mymodule/templates/myhash.erb)
Dynamic partitioning in Foreman kickstart templates
Foreman’s provisioning system allows creating provisioning templates with highly dynamic content. This article describes how to create dynamic content in your Foreman provisioning templates. While the example is related to dynamic partitioning in kickstart, the basic mechanisms for setting this up applies to any kind of template.
Foreman provisioning templates are written in ERB format. This allows having logic in the template itself based on user-defined host parameters. For example the Kickstart default template consumes a bunch of host parameters that allow you to define what kind of kickstart file you want Foreman to spit out for each host or host group. To give a simple example there’s the “lang” parameter which sets the value for “lang” kickstart option: