Hiera data in Puppet DSL
Written: 2018-03-20
Author: WhatsARanjit
Link: WhatsARanjit/puppet-hiera-backend
The problem
You want to use Hiera. You’ve just learned how to use the Puppet DSL. It’s out of your comfort zone, but you did it. Puppet DSL: you’ve heard is somewhat based on Ruby, but you don’t know Ruby, and you don’t need to know Ruby…awesome. But not it’s time to use Hiera. You’re told the default is to use something called ‘YAML’. YAML has it’s own syntax that’s totally separate from Puppet DSL. Why learn YAML? You just want to do Puppet.
The fix
We can use WhatsARanjit/puppet-hiera-backend
to express your Hiera data in
Puppet DSL, the language that you’ve already spent a great deal of time learning.
Install the module or put it in your Puppetfile.
Configuration
---
version: 5
defaults:
datadir: data
hierarchy:
- name: Experimental Puppet backend
data_hash: puppet_data
path: puppet.pp
Sample data .pp file
{
'string' => 'foo',
'array' => [
'one',
'two',
'three',
],
'hash' => {
'a' => 1,
'b' => 2,
'c' => 3,
}
}
Usage
[root@master ~]# puppet apply -e 'notice(hiera("string"))'
Notice: Scope(Class[main]): foo
Notice: Compiled catalog for master.puppetlabs.vm in environment production in 0.62 seconds
Notice: Applied catalog in 0.25 seconds
[root@master ~]# puppet apply -e 'notice(hiera("array"))'
Notice: Scope(Class[main]): [one, two, three]
Notice: Compiled catalog for master.puppetlabs.vm in environment production in 0.58 seconds
Notice: Applied catalog in 0.24 seconds
[root@master ~]# puppet apply -e 'notice(hiera("hash"))'
Notice: Scope(Class[main]): {a => 1, b => 2, c => 3}
Notice: Compiled catalog for master.puppetlabs.vm in environment production in 0.65 seconds
Notice: Applied catalog in 0.27 seconds