Setting up Hiera

Hiera needs to know one or two things before you can start using it, which are specified in the Hiera configuration file, named hiera.yaml (not to be confused this with Hiera data files, which are also YAML files, and we'll find about those later in this chapter.) Each Puppet environment has its own local Hiera config file, located at the root of the environment directory (for example, for the production environment, the local Hiera config file would be /etc/puppetlabs/code/environments/production/hiera.yaml).

Tip

Hiera can also use a global config file located at /etc/puppetlabs/puppet/hiera.yaml, which takes precedence over the per-environment file, but the Puppet documentation recommends you only use this config layer for certain exceptional purposes, such as temporary overrides; all your normal Hiera data and configuration should live at the environment layer.

The following example shows a minimal hiera.yaml file (hiera_minimal.config.yaml):

---
version: 5

defaults:
  datadir: data
  data_hash: yaml_data

hierarchy:
  - name: "Common defaults"
    path: "common.yaml"

YAML files begin with three dashes and a newline (---). This is part of the YAML format, not a Hiera feature; it's the syntax indicating the start of a new YAML document.

The most important setting in the defaults section is datadir. This tells Hiera in which directory to look for its data files. Conventionally, this is in a data/ subdirectory of the Puppet manifest directory, but you can change this if you need to.

Tip

Large organizations may find it useful to manage Hiera data files separately to Puppet code, perhaps in a separate Git repo (for example, you might want to give certain people permission to edit Hiera data, but not Puppet manifests).

The hierarchy section is also interesting. This tells Hiera which files to read for its data and in which order. In the example only Common defaults is defined, telling Hiera to look for data in a file called common.yaml. We'll see later in this chapter what else you can do with the hierarchy section.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.119.160.93