You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/_openvox_8x/_hiera_context_object.md
+13-10Lines changed: 13 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,3 +1,4 @@
1
+
<!-- markdownlint-disable MD041 -->
1
2
## The `Puppet::LookupContext` object
2
3
3
4
To support caching and other needs, Hiera provides backends a special `Puppet::LookupContext` object, which has several methods you can call for various effects.
@@ -24,7 +25,7 @@ The following methods are available:
24
25
25
26
### `not_found()`
26
27
27
-
[method_not]: #notfound
28
+
[method_not]: #not_found
28
29
29
30
Tells Hiera to move on to the next data source. Call this method when your function can't find a value for a given lookup. **This method does not return.**
30
31
@@ -44,13 +45,13 @@ In `lookup_key` and `data_dig` backends, you **must** call this method if you wa
44
45
45
46
### `environment_name()`
46
47
47
-
[method_env]: #environmentname
48
+
[method_env]: #environment_name
48
49
49
50
Returns the name of the environment whose hiera.yaml called the function. Returns `undef` (in Puppet) or `nil` (in Ruby) if the function was called by the global or module layer.
50
51
51
52
### `module_name()`
52
53
53
-
[method_module]: #modulename
54
+
[method_module]: #module_name
54
55
55
56
Returns the name of the module whose hiera.yaml called the function. Returns `undef` (in Puppet) or `nil` (in Ruby) if the function was called by the global or environment layer.
56
57
@@ -62,7 +63,9 @@ Caches a value, in a per-data-source private cache; also returns the cached valu
62
63
63
64
On future lookups in this data source, you can retrieve values with `cached_value(key)`. Cached values are immutable, but you can replace the value for an existing key. Cache keys can be anything valid as a key for a Ruby hash. (Notably, this means you can use `nil` as a key.)
64
65
65
-
For example, on its first invocation for a given YAML file, the built-in `eyaml_lookup_key` backend reads the whole file and caches it, and then decrypts only the specific value that was requested. On subsequent lookups into that file, it gets the encrypted value from the cache instead of reading the file from disk again. It also caches decrypted values, so that it won't have to decrypt again if the same key is looked up repeatedly.
66
+
For example, on its first invocation for a given YAML file, the built-in `eyaml_lookup_key` backend reads the whole file and caches it, and then decrypts only the specific value that was requested.
67
+
On subsequent lookups into that file, it gets the encrypted value from the cache instead of reading the file from disk again.
68
+
It also caches decrypted values, so that it won't have to decrypt again if the same key is looked up repeatedly.
66
69
67
70
The cache is also useful for storing session keys or connection objects for backends that access a network service.
68
71
@@ -77,39 +80,39 @@ If any inputs to a function change (for example, a path interpolates a local var
77
80
78
81
### `cache_all(hash)`
79
82
80
-
[method_cache_all]: #cacheallhash
83
+
[method_cache_all]: #cache_allhash
81
84
82
85
Caches all the key/value pairs from a given hash; returns `undef` (in Puppet) or `nil` (in Ruby).
83
86
84
87
### `cached_value(key)`
85
88
86
-
[method_cached]: #cachedvaluekey
89
+
[method_cached]: #cached_valuekey
87
90
88
91
Returns a previously cached value from the per-data-source private cache. Returns `nil` or `undef` if no value with this name has been cached. See [`cache(key, value)`][method_cache] above for more info about how the cache works.
89
92
90
93
### `cache_has_key(key)`
91
94
92
-
[method_haskey]: #cachehaskeykey
95
+
[method_haskey]: #cache_has_keykey
93
96
94
97
Checks whether the cache has a value for a given key yet. Returns `true` or `false`.
95
98
96
99
### `cached_entries()`
97
100
98
-
[method_allcached]: #cachedentries
101
+
[method_allcached]: #cached_entries
99
102
100
103
Returns everything in the per-data-source cache, as an iterable object. Note that this iterable object isn't a hash; if you want a hash, you can use `Hash($context.all_cached())` (in the Puppet language) or `Hash[context.all_cached()]` (in Ruby).
> **Note:** The header above uses Ruby's block syntax. To call this method in the Puppet language, you would use `cached_file_data(path) |content| { ... }`.
107
110
108
111
For best performance, use this method to read files in Hiera backends.
109
112
110
113
Returns the content of the specified file, as a string. If an optional block is provided, it passes the content to the block and returns the block's return value. For example, the built-in JSON backend uses a block to parse JSON and return a hash:
Copy file name to clipboardExpand all lines: docs/_openvox_8x/_hiera_options_hash.md
+4-3Lines changed: 4 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,3 +1,4 @@
1
+
<!-- markdownlint-disable MD041 -->
1
2
### The options hash
2
3
3
4
Hierarchy levels are configured in [hiera.yaml](./hiera_config_yaml_5.html). When calling a backend function, Hiera passes a modified version of that configuration as a hash.
@@ -6,13 +7,13 @@ The options hash contains the following keys:
6
7
7
8
*`path` --- The absolute path to a file on disk. Only present if the user set one of the `path`, `paths`, `glob`, or `globs` settings. Hiera ensures the file exists before passing it to the function.
8
9
9
-
> **Note:** If your backend uses data files, use the context object's [`cached_file_data` method][method_cached_file] to read them.
10
+
> **Note:** If your backend uses data files, use the context object's [`cached_file_data` method][method_cached_file] to read them.<!-- markdownlint-disable-line MD052 -->
10
11
*`uri` --- A URI that your function can use to locate a data source. Only present if the user set `uri` or `uris`. Hiera doesn't verify the URI before passing it to the function.
11
12
* Every key from the hierarchy level's `options` setting. In your documentation, make sure to list any options your backend requires or accepts. Note that the `path` and `uri` keys are reserved.
12
13
13
14
For example: this hierarchy level in hiera.yaml...
@@ -27,7 +28,7 @@ For example: this hierarchy level in hiera.yaml...
27
28
28
29
...would result in several different options hashes (depending on the current node's facts, whether the files exist, etc.), but they would all resemble the following:
> Although it's possible to set something other than the [certname][] as the node name (using either the [`node_name_fact`][node_name_fact] or [`node_name_value`][node_name_value] setting), we don't generally recommend it. It allows you to re-use one node certificate for many nodes, but it reduces security, makes it harder to reliably identify nodes, and can interfere with other features.
7
+
> Although it's possible to set something other than the [certname][] as the node name (using either the [`node_name_fact`][node_name_fact] or [`node_name_value`][node_name_value] setting), we don't generally recommend it. <!-- markdownlint-disable-line MD052 -->
8
+
> It allows you to re-use one node certificate for many nodes, but it reduces security, makes it harder to reliably identify nodes, and can interfere with other features.
7
9
>
8
10
> Setting a non-certname node name is **not officially supported** in Puppet Enterprise.
Copy file name to clipboardExpand all lines: docs/_openvox_8x/bgtm.md
+9-4Lines changed: 9 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -27,7 +27,9 @@ To help plan your module appropriately, consider:
27
27
28
28
It is standard practice for Puppet users to have 200 or more modules in an environment. Simple is better. Each module in your environment should contain related resources that enable it to accomplish a task. Create multiple modules for more complex needs. The practice of having many small, focused modules promotes code reuse and turns modules into building blocks.
29
29
30
-
As an example, let's take a look at the [`puppetlabs-puppetdb`](https://forge.puppet.com/puppetlabs/puppetdb) module. This module deals solely with the the setup, configuration, and management of PuppetDB. However, PuppetDB stores its data in a PostgreSQL database. Rather than having the module manage PostgreSQL, the author included the [`puppetlabs-postgresql`](https://forge.puppet.com/puppetlabs/postgresql) module as a dependency, leveraging the postgresql module's classes and resources to build out the right configuration for PuppetDB. Similarly, the `puppetdb-module` needs to manipulate the `puppet.conf` file in order to operate PuppetDB. Instead of having the `puppetdb-module` handle `puppet.conf` changes internally, the author used the [`puppetlabs-inifile`](https://forge.puppet.com/puppetlabs/inifile) module to enable `puppetlabs-puppetdb` to make only the required edits to `puppet.conf`.
30
+
As an example, let's take a look at the [`puppetlabs-puppetdb`](https://forge.puppet.com/puppetlabs/puppetdb) module. This module deals solely with the the setup, configuration, and management of PuppetDB. However, PuppetDB stores its data in a PostgreSQL database.
31
+
Rather than having the module manage PostgreSQL, the author included the [`puppetlabs-postgresql`](https://forge.puppet.com/puppetlabs/postgresql) module as a dependency, leveraging the postgresql module's classes and resources to build out the right configuration for PuppetDB.
32
+
Similarly, the `puppetdb-module` needs to manipulate the `puppet.conf` file in order to operate PuppetDB. Instead of having the `puppetdb-module` handle `puppet.conf` changes internally, the author used the [`puppetlabs-inifile`](https://forge.puppet.com/puppetlabs/inifile) module to enable `puppetlabs-puppetdb` to make only the required edits to `puppet.conf`.
31
33
32
34
## Structuring your module
33
35
@@ -54,7 +56,8 @@ In terms of class structure we recommend the following (more detail below):
54
56
55
57
#### `module`
56
58
57
-
The main class of any module must share the name of the module and be located in the `init.pp` file. The name and location of the main module class is extremely important, as it guides the [autoloader](./lang_namespaces.html#autoloader-behavior) behavior. The main class of a module is its interface point and ought to be the only parameterized class if possible. Limiting the parameterized classes to just the main class allows you to control usage of the entire module with the inclusion of a single class. This class should provide sensible defaults so that a user can get going with `include module`.
59
+
The main class of any module must share the name of the module and be located in the `init.pp` file. The name and location of the main module class is extremely important, as it guides the [autoloader](./lang_namespaces.html#autoloader-behavior) behavior.
60
+
The main class of a module is its interface point and ought to be the only parameterized class if possible. Limiting the parameterized classes to just the main class allows you to control usage of the entire module with the inclusion of a single class. This class should provide sensible defaults so that a user can get going with `include module`.
58
61
59
62
For instance, the main `ntp` class in the `ntp` module looks like this:
60
63
@@ -199,7 +202,8 @@ To maximize the usability of your module, make it flexible by adding parameters.
199
202
200
203
You must not hardcode data in your modules, and having more parameters is the best alternative. Hardcoding data in your module makes it inflexible, and means your module requires manifest changes to be used in even slightly different circumstances.
201
204
202
-
Avoid adding parameters that allow you to override templates. When your parameters allow template overrides, users can override your template with a custom template that contains additional hardcoded parameters. Hardcoded parameters in templates inhibits flexibility over time. It is far better to create more parameters and then modify the original template, or have a parameter which accepts an arbitrary chunk of text added to the template, than it is to override the template with a customized one.
205
+
Avoid adding parameters that allow you to override templates. When your parameters allow template overrides, users can override your template with a custom template that contains additional hardcoded parameters.
206
+
Hardcoded parameters in templates inhibits flexibility over time. It is far better to create more parameters and then modify the original template, or have a parameter which accepts an arbitrary chunk of text added to the template, than it is to override the template with a customized one.
203
207
204
208
For an example of a module that capitalizes on offering many parameters, please see [puppetlabs-apache](https://forge.puppet.com/puppetlabs/apache).
205
209
@@ -313,7 +317,8 @@ We encourage you to publish your modules on the [Puppet Forge](https://forge.pup
313
317
314
318
Sharing your modules allows other users to write improvements to the modules you make available and contribute them back to you, effectively giving you free improvements to your modules.
315
319
316
-
Additionally, publishing your modules to the Forge helps foster community among Puppet users, and allows other Puppet community members to download and use your module. If the Puppet community routinely releases and iterates on modules on the Forge, the quality of available modules increases dramatically and gives you access to more modules to download and modify for your own purposes. Details on how to publish modules to the Forge can be found in the [module publishing guide](./modules_publishing.html).
320
+
Additionally, publishing your modules to the Forge helps foster community among Puppet users, and allows other Puppet community members to download and use your module.
321
+
If the Puppet community routinely releases and iterates on modules on the Forge, the quality of available modules increases dramatically and gives you access to more modules to download and modify for your own purposes. Details on how to publish modules to the Forge can be found in the [module publishing guide](./modules_publishing.html).
0 commit comments