Forge Home


Type and providers for managing YAML and JSON data

Chris Spence



36,498 latest version

4.6 quality score

Version information

  • 1.0.3 (latest)
  • 1.0.2
  • 1.0.1
  • 1.0.0
released Feb 16th 2016
This version is compatible with:
  • Redhat

Start using this module

  • r10k or Code Manager
  • Bolt
  • Manual installation
  • Direct download

Add this declaration to your Puppetfile:

mod 'fiddyspence-hash_file', '1.0.3'
Learn more about managing modules with a Puppetfile

Add this module to a Bolt project:

bolt module add fiddyspence-hash_file
Learn more about using this module with an existing project

Manually install this module globally with Puppet module tool:

puppet module install fiddyspence-hash_file --version 1.0.3

Direct download is not typically how you would use a Puppet module to manage your infrastructure, but you may want to download the module in order to inspect the code.



fiddyspence/hash_file — version 1.0.3 Feb 16th 2016

This is a puppet module to manage a file as a hash of either JSON or YAML data.

If you've ever used Puppet to try and write out some JSON or YAML to a file from a hash of data you've generated, then you've probably ended up with a template something like:

<% @puppethash.keys.sort.each do |key| -%>
<%= key %>: <%= @puppethash[key] %>
<% end -%>

which is fine for a shallow object, but much much harder for deeper data. You do this because Hashes are unordered, and the YAML or JSON you get out changes every single time if you just @thing.to_json, which results in file changes every Puppet run. You probably didn't want this.

That situation no longer TM. This type and pair of providers treats the contents of the file as the actual object represented by the JSON or YAML and compares the objects through the wonderment of the Puppet RAL. It now no longer matters about Hash ordering, merely equivalence of the objects, which it turns out is quite easy.


fids$ cat /tmp/hiera/common.yaml
   baz: 'foo'
   moo: 1
   cow: '1'

fids$ cat /tmp/foo.pp
$foo = hiera(foo)
hash_file { '/tmp/hash': value => $foo, provider => 'yaml' }

fids$ puppet apply test.pp --modulepath=. --hiera_config=/etc/hiera.yaml
Notice: /Stage[main]/Main/Hash_file[/tmp/hash]/value: value changed '' to '{"bar"=>{"baz"=>"foo", "moo"=>1, "cow"=>"1"}}'

fids$ cat /tmp/hash
    baz: foo
    moo: 1
    cow: "1"


See LICENSE file


  • 15 April 2015 - initial release
  • 15 April 2015 - I probably lied about Windows