puppet Hierarchy

Puppet uses Hiera, using:: as the lookup key. For example, it looks up ntp::servers for the NTP class's $servers parameter. If a parameter still has no value, Puppet uses the default value from the parameter's default value expression in the class's definition.

Setting Up Hiera
*hiera.yaml is located in /etc/puppetlabs/puppet/
*backends: tells Hiera what kind of data sources it should process. In this case, we’ll be using YAML files.
*yaml: configures the YAML data backend.
*datadir: tells Hiera the location of the data sources.
*hierarchy: configures the data sources Hiera be using.
*Separate their hierarchies into directories.
*More specific data at the top.
*Least specific at the bottom.

hiera.yaml
---:backends:
- yaml
:yaml:
:datadir: "/etc/puppetlabs/code/environments/%{environment}/hieradata”
:hierarchy:
- "nodes/%{::trusted.certname}”
- common

Automatic Parameter Lookup
*Process of automatic parameter lookup:
*Look for parameters passed using the class {} declaration.
*If no parameter is passed, it will look in the Hiera data source for the parameter::parameterIf no parameter is passed, it will look in the Hiera data source for the parameter::parameter
*If it’s not found in the Hiera data source it will use the default set “common”

hiera Function
*hiera: Performs a standard priority lookup of the hierarchy and returns the most specific value for a given key. The returned value can be any type of data.
*A string key that Hiera searches for in the hierarchy. Required.
*An optional default value to return if Hiera doesn’t find anything matching the key.
*The optional name of an arbitrary hierarchy level to insert at the top of the hierarchy.

Example:
define apache::vhost(
$port,
)
#/etc/puppetlabs/code/environments/hieradata/common.yml
---
apache::vhost::port: 80

*hiera_array: Finds all matches of a key throughout the hierarchy and returns them as a
single flattened array of unique values. If any of the matched values are arrays, they’re
flattened and included in the results. This is called an array merge lookup.

Arguments:
*A string key that Hiera searches for in the hierarchy. Required.
*An optional default value to return if Hiera doesn’t find anything matching the key.
*The optional name of an arbitrary hierarchy level to insert at the top of the hierarchy.
*hiera_hash: Finds all matches of a key throughout the hierarchy and returns them in a
merged hash. If any of the matched hashes share keys, the final hash uses the value from the highest priority match. This is called a hash merge lookup.

A string key that Hiera searches for in the hierarchy. Required.
•An optional default value to return if Hiera doesn’t find anything matching the key.
•The optional name of an arbitrary hierarchy level to insert at the top of the hierarchy.





Recent Comments

No comments

Leave a Comment