Puppet Hiera 5 Setup

Hiera is Puppet’s built-in key/value data lookup system. By default, it uses simple YAML or JSON files, although you can extend it to work with almost any data source. Hiera is the most flexible way to get configuration data into Puppet. Hiera is immensely powerful, and with great power comes great responsibility. Specifically, you’re responsible for making your infrastructure maintainable and legible, both for your co-workers and for your future self.

Let’s Started

The default location for the global hiera.yaml is $confdir/hiera.yaml. Depending on your platform, that’s usually at /etc/puppetlabs/puppet/hiera.yaml. You can use the hiera_config setting in puppet.conf to change the location of the global hiera.yaml.

[root@puppet ~]# cat /etc/puppetlabs/puppet/puppet.conf
# This file can be used to override the default puppet settings.
# See the following links for more details on what settings are available:
# - https://puppet.com/docs/puppet/latest/config_important_settings.html
# - https://puppet.com/docs/puppet/latest/config_about_settings.html
# - https://puppet.com/docs/puppet/latest/config_file_main.html
# - https://puppet.com/docs/puppet/latest/configuration.html
vardir = /opt/puppetlabs/server/data/puppetserver
logdir = /var/log/puppetlabs/puppetserver
rundir = /var/run/puppetlabs/puppetserver
pidfile = /var/run/puppetlabs/puppetserver/puppetserver.pid
codedir = /etc/puppetlabs/code
hiera_config = $confdir/hiera.yaml

dns_alt_names = puppet,puppet.exabig.com
environment_timeout = unlimited
storeconfigs = true
storeconfigs_backend = puppetdb

certname = puppet.exabig.com
server = puppet.exabig.com
environment = production
runinterval = 1h

[root@puppet ~]#

Hiera Config

Hiera’s config file is called hiera.yaml. It configures the hierarchy for a given layer of data.

[root@puppet ~]# cat /etc/puppetlabs/puppet/hiera.yaml
# Hiera 5 Global configuration file

version: 5
  datadir: "/etc/puppetlabs/code/environments/%{environment}/hieradata"
  data_hash: yaml_data
  - name: "Common data"
    path: "common.yaml"
[root@puppet ~]#
[root@puppet ~]#
[root@puppet ~]# cat /etc/puppetlabs/code/environments/production/hieradata/common.yaml
krishna: '1000'
chandra: '5000'
prajapati: 10000
[root@puppet ~]#

After modifying hiera configs, restart puppetserver services.

Accessing hiera data using cli

Once you have the hiera data ready in the puppet server, you can check the values using hiera CLI.

[root@puppet ~]# cat /etc/puppetlabs/code/environments/production/hieradata/common.yaml
krishna: '1000'
chandra: '5000'
prajapati: 10000
[root@puppet ~]#
[root@puppet ~]# puppet lookup krishna
--- '1000'
[root@puppet ~]#
[root@puppet ~]# puppet lookup chandra
--- '5000'
[root@puppet ~]#
[root@puppet ~]# puppet lookup prajapati
--- 10000
[root@puppet ~]#


We have successfully setup hiera 5. Now, hiera is ready to serve the parameters.

Enjoy !!!

Leave a Reply

Your email address will not be published. Required fields are marked *