Hiera's main reason for existence is data separation. In practical terms, this means that we can simplify code that includes the selection of the data to use in the very code, as in this example:
$dns_server = $zone ? { 'it' => '1.2.3.4', default => '8.8.8.8', } class { '::resolver': server => $dns_servers, }
It can be converted into something where there's no trace of local settings, as in the following:
$dns_server = hiera('dns_server') class { '::resolver': server => $dns_servers, }
Since version 3 of Puppet, the above code can be simplified even more by just including the ::resolver
class and Hiera will look up in its data files the value to resolve the resolver::server
key.
The advantages of having data (in this case the IP of the DNS server, whatever is the logic to elaborate it) in a separate place are as follows:
We can manage and modify data without changing our code
Different people can work on data and on code
Hiera pluggable backend system...