Forge Home

hash_file

Type and providers for managing YAML and JSON data

56,869 downloads

53,958 latest version

4.6 quality score

We run a couple of automated
scans to help you access a
module's quality. Each module is
given a score based on how well
the author has formatted their
code and documentation and
modules are also checked for
malware using VirusTotal.

Please note, the information below
is for guidance only and neither of
these methods should be considered
an endorsement by Puppet.

Version information

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

Start using this module

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

Add this module to your Puppetfile:

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

Add this module to your 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.

Download

Documentation

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.

EXAMPLE USAGE:

fids$ cat /tmp/hiera/common.yaml
---
foo:
  bar:
   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
---
  bar:
    baz: foo
    moo: 1
    cow: "1"

License:

See LICENSE file

Changelog:

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