To use Hiera with Puppet, you'll need to set up your Hiera configuration and integrate it into your Puppet control repository. Hiera allows you to separate data from your Puppet manifests, making your configurations more modular and manageable.
Here's a high-level outline:
-
Set Up Hiera Configuration:
Create or edit thehiera.yaml
file in the root directory of your Puppet control repository. Define the hierarchy and the data format (YAML is common).Example:
--- version: 5 hierarchy: - name: "Nodes" path: "nodes/%{::trusted.certname}.yaml" - name: "Operating System" path: "os/%{facts.os.family}.yaml" - name: "Common" path: "common.yaml"
-
Store Your Data:
Organize your data in a directory structure that matches your hierarchy. For example:data/ ├── common.yaml ├── nodes/ │ └── node1.example.com.yaml └── os/ └── RedHat.yaml
Each YAML file should contain key-value pairs for the data you want to use.
-
Reference Hiera Data in Manifests:
Use thelookup
function in your Puppet manifests to retrieve data from Hiera.Example:
$package_name = lookup('package_name') package { $package_name: ensure => installed, }
-
Test and Apply:
Usepuppet lookup
on the command line to test your Hiera configuration and data retrieval. Once you're satisfied, apply your changes using Puppet.