Skip to content

Commit 57c2b6d

Browse files
authored
Merge pull request #74 from miharp/fix/hiera-intro-restore
Restore Hiera intro and config yaml 5 pages from Puppet 5.4 archive
2 parents fbb2981 + c85f558 commit 57c2b6d

4 files changed

Lines changed: 512 additions & 6 deletions

File tree

docs/_openvox_8x/hiera_config_yaml_3.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
---
2+
layout: default
23
title: "Hiera: Legacy config file syntax (hiera.yaml v3)"
34
---
45

docs/_openvox_8x/hiera_config_yaml_4.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
---
2+
layout: default
23
title: "Hiera: Legacy config file syntax (hiera.yaml v4)"
34
---
45

Lines changed: 359 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,367 @@
11
---
2+
layout: default
23
title: "Configuring Hiera"
34
---
45

6+
[hierarchy]: ./hiera_intro.html#hiera-hierarchies
7+
[layers]: ./hiera_intro.html#hieras-three-config-layers
8+
[confdir]: ./dirs_confdir.html
9+
[module]: ./modules_fundamentals.html
10+
[yaml]: http://www.yaml.org/YAML_for_ruby.html
11+
[variables]: ./hiera_merging.html#interpolating-variables
12+
[interpolation]: ./hiera_interpolation.html
13+
[eyaml]: https://github.com/voxpupuli/hiera-eyaml
14+
[custom puppet function]: ./functions_basics.html
15+
[backends]: ./hiera_custom_backends.html
516

6-
This page is no longer maintained in Github. Contributions from the Puppet community are still very welcome.
17+
The Hiera configuration file is called hiera.yaml. It configures the hierarchy for a given layer of data.
718

8-
- Open a Jira ticket in the DOCUMENT project here: https://tickets.puppetlabs.com/projects/DOCUMENT/ Let us know the URL of the page, and describe the changes you think it needs.
19+
Related topics: [hierarchy][hierarchy], [layers][layers].
920

10-
- Email docs@puppet.com if you have questions about contributing to the documentation.
21+
## Location of hiera.yaml files
1122

23+
There are several hiera.yaml files in a typical deployment. Hiera uses three layers of configuration, and the module and environment layers typically have multiple instances.
24+
25+
The configuration file locations for each layer:
26+
27+
Layer | Location | Example
28+
------------|-------------------------------------------------|--------
29+
Global | [`$confdir`][confdir]`/hiera.yaml` | `/etc/puppetlabs/puppet/hiera.yaml` `C:\ProgramData\PuppetLabs\puppet\etc\hiera.yaml`
30+
Environment | [`<ENVIRONMENT>`](./environments_about.html)`/hiera.yaml` | `/etc/puppetlabs/code/environments/production/hiera.yaml` `C:\ProgramData\PuppetLabs\code\environments\production\hiera.yaml`
31+
Module | [`<MODULE>`][module]`/hiera.yaml` | `/etc/puppetlabs/code/environments/production/modules/ntp/hiera.yaml` `C:\ProgramData\PuppetLabs\code\environments\production\modules\ntp\hiera.yaml`
32+
33+
> Note: You can change the location for the global layer's hiera.yaml with OpenVox's `hiera_config` setting.
34+
35+
Hiera searches for data in the following order: global → environment → module. For more information, see [Hiera configuration layers][layers].
36+
37+
Related topics: [$confdir][confdir], [`<MODULE>`][module].
38+
39+
## Config file syntax (hiera.yaml v5)
40+
41+
`hiera.yaml` is a YAML file, containing a hash with up to four top-level keys:
42+
43+
- `version` - Required. Must be the number 5, with no quotes.
44+
- `hierarchy` - An array of hashes, which configures the levels of the hierarchy.
45+
- `default_hierarchy` - An array of hashes, which sets a default hierarchy to be used only if the normal hierarchy entries do not result in a value. Only allowed in a module's hiera.yaml.
46+
- `defaults` - A hash, which can set a default datadir, backend, and options for hierarchy levels.
47+
48+
```yaml
49+
---
50+
version: 5
51+
defaults: # Used for any hierarchy level that omits these keys.
52+
datadir: data # This path is relative to hiera.yaml's directory.
53+
data_hash: yaml_data # Use the built-in YAML backend.
54+
55+
hierarchy:
56+
- name: "Per-node data" # Unique human-readable name.
57+
path: "nodes/%{trusted.certname}.yaml" # File path, relative to datadir.
58+
# ^^^ IMPORTANT: include the file extension!
59+
60+
- name: "Per-datacenter business group data" # Uses custom facts.
61+
path: "location/%{facts.whereami}/%{facts.group}.yaml"
62+
63+
- name: "Global business group data"
64+
path: "groups/%{facts.group}.yaml"
65+
66+
- name: "Per-datacenter secret data (encrypted)"
67+
lookup_key: eyaml_lookup_key # Uses non-default backend.
68+
path: "secrets/%{facts.whereami}.eyaml"
69+
options:
70+
pkcs7_private_key: /etc/puppetlabs/puppet/eyaml/private_key.pkcs7.pem
71+
pkcs7_public_key: /etc/puppetlabs/puppet/eyaml/public_key.pkcs7.pem
72+
73+
- name: "Per-OS defaults"
74+
path: "os/%{facts.os.family}.yaml"
75+
76+
- name: "Common data"
77+
path: "common.yaml"
78+
```
79+
80+
Related topics: [YAML][yaml]
81+
82+
### The default configuration
83+
84+
If you omit the `hierarchy` or `defaults` keys, Hiera uses the following default values:
85+
86+
```yaml
87+
---
88+
version: 5
89+
hierarchy:
90+
- name: Common
91+
path: common.yaml
92+
defaults:
93+
data_hash: yaml_data
94+
datadir: data
95+
```
96+
97+
These defaults are only used if the file is present and specifies `version: 5`. If hiera.yaml is absent, it disables Hiera for that layer. If it specifies a different version, different defaults apply.
98+
99+
## The defaults key
100+
101+
The `defaults` key sets default values for the lookup function and `datadir` keys, which lets you omit those keys in your hierarchy levels.
102+
103+
The value of `defaults` must be a hash, which can have up to three keys: `datadir`, `options`, and one of the mutually exclusive lookup function keys.
104+
105+
### datadir
106+
107+
A default value for `datadir`, used for any file-based hierarchy level that doesn't specify its own. If not given, the `datadir` is the directory `data` in the same directory as the `hiera.yaml` configuration file.
108+
109+
### options
110+
111+
A default value for options, used for any hierarchy level that does not specify its own.
112+
113+
### The lookup function keys
114+
115+
Used for any hierarchy level that doesn't specify its own. This must be one of:
116+
117+
- `data_hash` - produces a hash of key-value pairs (typically from a data file)
118+
- `lookup_key` - produces values key by key (typically for a custom data provider)
119+
- `data_dig` - produces values key by key (for a more advanced data provider)
120+
- `hiera3_backend` - a data provider that calls out to a legacy Hiera 3 backend (global layer only)
121+
122+
For the built-in data providers - YAML, JSON, and HOCON - the key is always `data_hash` and the value is one of `yaml_data`, `json_data`, or `hocon_data`. To set a custom data provider as the default, see the data provider documentation. Whichever key you use, the value must be the name of the custom OpenVox function that implements the lookup function.
123+
124+
Related topics: [custom backends][backends], [custom OpenVox function][custom puppet function].
125+
126+
## The hierarchy key
127+
128+
The `hierarchy` key configures the levels of the hierarchy.
129+
130+
## The default_hierarchy key
131+
132+
The `default_hierarchy` key is a top-level key. It works exactly like the hierarchy key, but its values are used only if the normal hierarchy entries in the same module, or any of the higher precedence layers (environment or global) does not result in a value. Within this default hierarchy, the normal merging rules apply. However, the `default_hierarchy` is not permitted in environment or global layers.
133+
134+
Related topics: [hierarchies][hierarchy].
135+
136+
## The hierarchy key: write an array of hashes
137+
138+
The value of `hierarchy` must be an array of hashes.
139+
140+
1. Begin each level of the hierarchy with:
141+
142+
- Two spaces of indentation.
143+
- A hyphen (`-`).
144+
- Another space after the hyphen.
145+
- The first key of that level's hash.
146+
147+
2. Indent the rest of the hash's keys by four spaces, so they line up with the first key.
148+
149+
3. Put an empty line between hashes, to visually distinguish them.
150+
151+
```yaml
152+
hierarchy:
153+
- name: "Per-node data"
154+
path: "nodes/%{trusted.certname}.yaml"
155+
156+
- name: "Per-datacenter business group data"
157+
path: "location/%{facts.whereami}/%{facts.group}.yaml"
158+
```
159+
160+
## Configuring a hierarchy level: built-in backends
161+
162+
Hiera has three built-in backends: YAML, JSON, and HOCON. All of these use files as data sources.
163+
164+
You can use any combination of these backends in a hierarchy, and can also combine them with custom backends. But if most of your data is in one file format, set default values for the `datadir` and `data_hash` keys.
165+
166+
Each YAML/JSON/HOCON hierarchy level needs the following keys:
167+
168+
- `name` — A unique name for this level, shown in debug messages and `--explain` output.
169+
- `path`, `paths`, `glob`, `globs`, or `mapped_paths` (choose one) — The data files to use for this hierarchy level.
170+
- These paths are relative to the datadir, they support variable interpolation, and they require a file extension. See "Specifying file paths" for more details.
171+
- `data_hash` — Which backend to use. Can be omitted if you set a default. The value must be one of the following:
172+
- `yaml_data` for YAML.
173+
- `json_data` for JSON.
174+
- `hocon_data` for HOCON.
175+
- `datadir` — The directory where data files are kept. Can be omitted if you set a default.
176+
- This path is relative to hiera.yaml's directory: if the config file is at `/etc/puppetlabs/code/environments/production/hiera.yaml` and the datadir is set to data, the full path to the data directory is `/etc/puppetlabs/code/environments/production/data`.
177+
- In the global layer, you can optionally set the datadir to an absolute path; in the other layers, it must always be relative.
178+
179+
Related topics: [variable interpolation][variables], [YAML][yaml].
180+
181+
### Specifying file paths
182+
183+
Options for specifying a file path:
184+
185+
Key | Data type | Expected value
186+
--------|-----------|---------------
187+
`path` | String | One file path.
188+
`paths` | Array | Any number of file paths. This acts like a sub-hierarchy: if multiple files exist, Hiera searches all of them, in the order in which they're written.
189+
`glob` | String | One shell-like glob pattern, which might match any number of files. If multiple files are found, Hiera searches all of them in alphanumerical order.
190+
`globs` | Array | Any number of shell-like glob patterns. If multiple files are found, Hiera searches all of them in alphanumerical order (ignoring the order of the globs).
191+
`mapped_paths` | Array or Hash | A fact that is a collection (array or hash) of values. Hiera expands these values to produce an array of paths.
192+
193+
> Note: You can only use one of these keys in a given hierarchy level.
194+
195+
Explicit file extensions are required, for example, `common.yaml`, not `common`.
196+
197+
File paths are relative to the `datadir`: if the full datadir is `/etc/puppetlabs/code/environments/production/data` and the file path is set to `"nodes/%{trusted.certname}.yaml"`, the full path to the file is `/etc/puppetlabs/code/environments/production/data/nodes/<NODE NAME>.yaml`.
198+
199+
> Note: Hierarchy levels should interpolate variables into the path.
200+
201+
Globs are implemented with Ruby's `Dir.glob` method:
202+
203+
- One asterisk (`*`) matches a run of characters.
204+
- Two asterisks (`**`) matches any depth of nested directories.
205+
- A question mark (`?`) matches one character.
206+
- Comma-separated lists in curly braces (`{one,two}`) match any option in the list.
207+
- Sets of characters in square brackets (`[abcd]`) match any character in the set.
208+
- A backslash (`\`) escapes special characters.
209+
210+
Example:
211+
212+
{% raw %}
213+
214+
```yaml
215+
- name: "Domain or network segment"
216+
glob: "network/**/{%{facts.networking.domain},%{facts.networking.interfaces.en0.bindings.0.network}}.yaml"
217+
```
218+
219+
{% endraw %}
220+
221+
The `mapped_paths` key must contain three string elements, in the following order:
222+
223+
- A scope variable that points to a collection of strings.
224+
- The variable name that will be mapped to each element of the collection.
225+
- A template where that variable can be used in interpolation expressions.
226+
227+
For example, a fact named `$services` contains the array `["a", "b", "c"]`. The following configuration has the same results as if paths had been specified to be `[service/a/common.yaml, service/b/common.yaml, service/c/common.yaml]`.
228+
229+
```yaml
230+
- name: Example
231+
mapped_paths: [services, tmp, "service/%{tmp}/common.yaml"]
232+
```
233+
234+
Related topics: [interpolate][interpolation], [hierarchies][hierarchy].
235+
236+
## Configuring a hierarchy level: hiera-eyaml
237+
238+
Hiera 5 includes a native interface for the Hiera eyaml extension, which keeps data encrypted on disk but lets OpenVox read it during catalog compilation.
239+
240+
To learn how to create keys and edit encrypted files, see the [Hiera eyaml documentation](https://github.com/voxpupuli/hiera-eyaml).
241+
242+
Within `hiera.yaml`, the eyaml backend resembles the standard built-in backends, with a few differences: it uses `lookup_key` instead of `data_hash`, and requires an `options` key to locate decryption keys. Note that the eyaml backend can read regular yaml files as well as yaml files with encrypted data.
243+
244+
> **Important**: To use the eyaml backend, you must have the `hiera-eyaml` gem installed where OpenVox can use it. To enable eyaml on the command line and with `puppet apply`, use `sudo /opt/puppetlabs/puppet/bin/gem install hiera-eyaml`.
245+
246+
Each eyaml hierarchy level needs the following keys:
247+
248+
- `name` — A unique name for this level, shown in debug messages and `--explain` output.
249+
- `lookup_key` — Which backend to use. The value must be `eyaml_lookup_key`. Use this instead of the `data_hash` setting.
250+
- `path`, `paths`, `mapped_paths`, `glob`, or `globs` (choose one) — The data files to use for this hierarchy level. These paths are relative to the datadir, they support variable interpolation, and they require a file extension. In this case, you'll usually use `.eyaml`. They work the same way they do for the standard backends.
251+
- `datadir` — The directory where data files are kept. Can be omitted if you set a default. Works the same way it does for the standard backends.
252+
- `options` — A hash of options specific to `hiera-eyaml`, mostly used to configure decryption. For the default encryption method, this hash must have the following keys:
253+
- `pkcs7_private_key` — The location of the PKCS7 private key to use.
254+
- `pkcs7_public_key` — The location of the PKCS7 public key to use.
255+
- If you use an alternate encryption plugin, its docs should specify which options to set. Set an `encrypt_method` option, plus some plugin-specific options to replace the `pkcs7` ones.
256+
- You can use normal strings as keys in this hash; you don't need to use symbols.
257+
258+
The file path key and the options key both support variable interpolation.
259+
260+
An example hierarchy level:
261+
262+
```yaml
263+
hierarchy:
264+
- name: "Per-datacenter secret data (encrypted)"
265+
lookup_key: eyaml_lookup_key
266+
path: "secrets/%{facts.whereami}.eyaml"
267+
options:
268+
pkcs7_private_key: /etc/puppetlabs/puppet/eyaml/private_key.pkcs7.pem
269+
pkcs7_public_key: /etc/puppetlabs/puppet/eyaml/public_key.pkcs7.pem
270+
```
271+
272+
Related topics: [Hiera eyaml][eyaml], [variable interpolation][interpolation].
273+
274+
## Configuring a hierarchy level: legacy Hiera 3 backends
275+
276+
> Note: This feature is a temporary measure to let you start using new features while waiting for backend updates.
277+
278+
If you rely on custom data backends designed for Hiera 3, you can use them in your global hierarchy. They are not supported at the environment or module layers.
279+
280+
Each legacy hierarchy level needs the following keys:
281+
282+
- `name` — A unique name for this level, shown in debug messages and `--explain` output.
283+
- `path` or `paths` (choose one) — The data files to use for this hierarchy level.
284+
- For file-based backends, include the file extension, even though you would have omitted it in the v3 hiera.yaml file.
285+
- For non-file backends, don't use a file extension.
286+
- `hiera3_backend` — The legacy backend to use. This is the same name you'd use in the v3 config file's `:backends` key.
287+
- `datadir` — The directory where data files are kept. Set this only if your backend required a `:datadir` setting in its backend-specific options.
288+
- This path is relative to hiera.yaml's directory: if the config file is at `/etc/puppetlabs/code/environments/production/hiera.yaml` and the datadir is set to `data`, the full path to the data directory is `/etc/puppetlabs/code/environments/production/data`. Note that Hiera v3 uses 'hieradata' instead of 'data'.
289+
- In the global layer, you can optionally set the datadir to an absolute path.
290+
- `options` — A hash, with any backend-specific options (other than `datadir`) required by your backend. In the v3 config, this would have been in a top-level key named after the backend.
291+
292+
You can use normal strings as keys. Hiera converts them to symbols for the backend.
293+
294+
The following example shows roughly equivalent v3 and v5 hiera.yaml files using legacy backends:
295+
296+
```yaml
297+
# hiera.yaml v3
298+
---
299+
:backends:
300+
- mongodb
301+
- xml
302+
303+
:mongodb:
304+
:connections:
305+
:dbname: hdata
306+
:collection: config
307+
:host: localhost
308+
309+
:xml:
310+
:datadir: /some/other/dir
311+
312+
:hierarchy:
313+
- "%{trusted.certname}"
314+
- "common"
315+
316+
317+
# hiera.yaml v5
318+
---
319+
version: 5
320+
hierarchy:
321+
- name: MongoDB
322+
hiera3_backend: mongodb
323+
paths:
324+
- "%{trusted.certname}"
325+
- common
326+
options:
327+
connections:
328+
dbname: hdata
329+
collection: config
330+
host: localhost
331+
332+
- name: Data in XML
333+
hiera3_backend: xml
334+
datadir: /some/other/dir
335+
paths:
336+
- "%{trusted.certname}.xml"
337+
- common.xml
338+
```
339+
340+
## Configuring a hierarchy level: general format
341+
342+
Hiera supports custom backends.
343+
344+
See the backend's documentation for configuring hierarchy levels.
345+
346+
Each hierarchy level is represented by a hash which needs the following keys:
347+
348+
- `name` — A unique name for this level, shown in debug messages and `--explain` output.
349+
- A backend key, which must be one of:
350+
- `data_hash`
351+
- `lookup_key`
352+
- `data_dig` - a more specialized form of `lookup_key`, suitable when the backend is for a database. `data_dig` resolves dot separated keys, whereas `lookup_key` does not.
353+
- `hiera3_backend` (global layer only)
354+
- A path or URI key - only if required by the backend. These keys support variable interpolation. The following path/URI keys are available:
355+
- `path`
356+
- `paths`
357+
- `mapped_paths`
358+
- `glob`
359+
- `globs`
360+
- `uri`
361+
- `uris` - these paths or URIs work the same way they do for the built-in backends. Hiera handles the work of locating files, so any backend that supports `path` automatically supports `paths`, `glob`, and `globs`. `uri` (string) and `uris` (array) can represent any kind of data source. Hiera does not ensure URIs are resolvable before calling the backend, and does not need to understand any given URI schema. A backend can omit the path/URI key, and rely wholly on the `options` key to locate its data.
362+
- `datadir` — The directory where data files are kept: the path is relative to hiera.yaml's directory. Only required if the backend uses the `path`, `paths`, `glob`, and `globs` keys, and can be omitted if you set a default.
363+
- `options` — A hash of extra options for the backend; for example, database credentials or the location of a decryption key. All values in the `options` hash support variable interpolation.
364+
365+
Whichever key you use, the value must be the name of a function that implements the backend API. Note that the choice here is made by the implementer of the particular backend, not the user.
366+
367+
Related topics: [custom OpenVox function][custom puppet function], [custom backends][backends], [variable interpolation][interpolation].

0 commit comments

Comments
 (0)