In a nutshell Hiera data bindings enables Puppet to automatically look up parameters in Hiera. Before I learnt about it I had a whole lot of code that looked like this:
$relayhost = hiera('relayhost')
$mynetworks = hiera('mynetworks')
$inet_interfaces = hiera('inet_interfaces')
with a yaml file that looked like this: relayhost: mail.example.co.za
inet_interfaces: localhost
mynetworks: 192.168.1.0/24
With Hiera data bindings you can get rid of all this random hiera('param_to_lookup') in your code and hiera will look up the values automatically. The first thing you will need to do is use parametrized classes, which you should be using already. My environment has a lot of legacy modules which had/have to be updated to use parametrized classes, we typically declared most of our variables in a params class.A parametrized class has all your variables set at the top of the class. This makes it easily configurable and more portable. An example of a parametrized class:
class postfix::client (
$relayhost,
$inet_interfaces = 'localhost',
$mynetworks,
...
) {
Here we define our variables with an optional default value. We can then use this class by overriding the defaults when we call it (This also overrides Hiera): class { postfix::client:
relayhost => "test",
inet_interfaces => "192.168.1.5",
mynetworks => "192.168.1.0/24",
}
The problem with this method is if you have many hosts with custom setups, you have all these scattered class definitions all over the place, instead of just declaring it in once. If you are using a parametrized class, puppet can now automagically look up the values from Hiera. You need to structure your Hiera .yaml files to have have the following structure "module::class::variable". postfix::client::relayhost: mail.example.co.za
postfix::client::inet_interfaces: localhost
postfix::client::mynetworks: undef
Now you can declare your class in your base class as follows: class { postfix::client: }
when puppet runs it will look up the variables in Hiera overriding the modules defaults.





