Skip to content

Commit 802ee6b

Browse files
authored
Merge pull request #985 from puppetlabs/6.17-release
Adding build for puppet 6.16 long-lived
2 parents 8d64758 + 2b06041 commit 802ee6b

File tree

114 files changed

+48397
-1
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

114 files changed

+48397
-1
lines changed

source/_config.yml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,6 @@ documents:
122122
nav: ./_puppet_toc.html
123123
my_versions:
124124
puppetserver: "latest"
125-
126125
# Puppet latest dependencies
127126
/puppetserver/latest:
128127
doc: puppetserver
@@ -136,6 +135,17 @@ documents:
136135
puppet: "latest"
137136
hide: true
138137

138+
# Puppet 6.16
139+
/docs/puppet/6.16:
140+
doc: puppet
141+
version: "6.16"
142+
nav: ./_puppet_toc.html
143+
my_versions:
144+
puppetserver: "latest"
145+
hide: true
146+
# Puppet 6.16 dependencies (As of 10 July 2020, this is just server latest.
147+
# If Server ends up cutting a branch for 6.12.x, we'll need to add that here.)
148+
139149
# Puppet 5.5
140150
/docs/puppet/5.5:
141151
doc: puppet
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
In this version of Puppet, the environment.conf file is only allowed to override five settings:
2+
3+
- `modulepath`
4+
- `manifest`
5+
- `config_version`
6+
- `environment_timeout`
7+
- `static_catalogs`
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
``` yaml
2+
---
3+
version: 5
4+
defaults: # Used for any hierarchy level that omits these keys.
5+
datadir: data # This path is relative to hiera.yaml's directory.
6+
data_hash: yaml_data # Use the built-in YAML backend.
7+
8+
hierarchy:
9+
- name: "Per-node data" # Human-readable name.
10+
path: "nodes/%{trusted.certname}.yaml" # File path, relative to datadir.
11+
# ^^^ IMPORTANT: include the file extension!
12+
13+
- name: "Per-datacenter business group data" # Uses custom facts.
14+
path: "location/%{facts.whereami}/%{facts.group}.yaml"
15+
16+
- name: "Global business group data"
17+
path: "groups/%{facts.group}.yaml"
18+
19+
- name: "Per-datacenter secret data (encrypted)"
20+
lookup_key: eyaml_lookup_key # Uses non-default backend.
21+
path: "secrets/%{facts.whereami}.eyaml"
22+
options:
23+
pkcs7_private_key: /etc/puppetlabs/puppet/eyaml/private_key.pkcs7.pem
24+
pkcs7_public_key: /etc/puppetlabs/puppet/eyaml/public_key.pkcs7.pem
25+
26+
- name: "Per-OS defaults"
27+
path: "os/%{facts.os.family}.yaml"
28+
29+
- name: "Common data"
30+
path: "common.yaml"
31+
```
Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
## The `Puppet::LookupContext` object
2+
3+
To support caching and other needs, Hiera provides backends a special `Puppet::LookupContext` object, which has several methods you can call for various effects.
4+
5+
* In [Ruby functions](./functions_ruby_overview.html), this is a normal Ruby object of class `Puppet::LookupContext`, and you can call methods with standard Ruby syntax (like `context.not_found`).
6+
* In [Puppet language functions](./lang_write_functions_in_puppet.html), the context object appears as a special data type (Object) that has methods attached. Right now, there isn't anything else in the Puppet language that acts like this.
7+
8+
You can call its methods using Puppet's [chained function call syntax](./lang_functions.html#chained-function-calls) with the method name instead of a normal function --- for example, `$context.not_found`. For methods that take a block, use Puppet's lambda syntax (parameters outside block) instead of Ruby's block syntax (parameters inside block).
9+
10+
The following methods are available:
11+
12+
* [`not_found()`][method_not], for bailing out of a lookup.
13+
* [`interpolate(value)`][method_interpolate], for handing Hiera interpolation tokens in values.
14+
* [`environment_name()`][method_env], to find out which environment this is.
15+
* [`module_name()`][method_module], to find out which module this is.
16+
* [`cache(key, value)`][method_cache], for caching information between function runs.
17+
* [`cache_all(hash)`][method_cache_all], for caching several things at once.
18+
* [`cached_value(key)`][method_cached], for retrieving cached values.
19+
* [`cache_has_key(key)`][method_haskey], for checking the cache.
20+
* [`cached_entries()`][method_allcached], for dumping the whole cache.
21+
* [`cached_file_data(path) {|content| ...}`][method_cached_file], for high-performance reading of data files.
22+
* [`explain() || { 'message' }`][method_explain], for helpful debug messages.
23+
24+
25+
### `not_found()`
26+
27+
[method_not]: #notfound
28+
29+
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+
For `data_hash` backends, use this when the requested data source doesn't exist. (If it exists and is empty, return an empty hash.) Missing data sources aren't an issue when using `path`/`glob` settings, but are important for backends that locate their own data sources.
32+
33+
For `lookup_key` and `data_dig` backends, use this when a requested key isn't present in the data source or the data source doesn't exist. Don't return `undef`/`nil` for missing keys, since that's a legal value that can be set in data.
34+
35+
### `interpolate(value)`
36+
37+
[method_interpolate]: #interpolatevalue
38+
39+
Returns the provided value, but with any Hiera interpolation tokens (like `%{variable}` or `%{lookup('key')}`) replaced by their value. This lets you opt-in to allowing Hiera-style interpolation in your backend's data sources. Works recursively on arrays and hashes; hashes can interpolate into both keys and values.
40+
41+
In `data_hash` backends, interpolation is automatically supported and you don't need to call this method.
42+
43+
In `lookup_key` and `data_dig` backends, you **must** call this method if you want to support interpolation; if you don't, Hiera assumes you have your own thing going on.
44+
45+
### `environment_name()`
46+
47+
[method_env]: #environmentname
48+
49+
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+
### `module_name()`
52+
53+
[method_module]: #modulename
54+
55+
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+
### `cache(key, value)`
58+
59+
[method_cache]: #cachekey-value
60+
61+
Caches a value, in a per-data-source private cache; also returns the cached value.
62+
63+
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+
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+
67+
The cache is also useful for storing session keys or connection objects for backends that access a network service.
68+
69+
#### Cache lifetime and scope
70+
71+
Each `Puppet::LookupContext` cache only lasts for the duration of the current catalog compilation; a node can't access values cached for a previous node.
72+
73+
Hiera creates a separate cache for each *combination of inputs for a function call,* including inputs like `name` that are configured in hiera.yaml but not passed to the function. So not only does each hierarchy level have its own cache, but hierarchy levels that use multiple paths have a separate cache for each path.
74+
75+
If any inputs to a function change (for example, a path interpolates a local variable whose value changes between lookups), Hiera uses a fresh cache.
76+
77+
78+
### `cache_all(hash)`
79+
80+
[method_cache_all]: #cacheallhash
81+
82+
Caches all the key/value pairs from a given hash; returns `undef` (in Puppet) or `nil` (in Ruby).
83+
84+
### `cached_value(key)`
85+
86+
[method_cached]: #cachedvaluekey
87+
88+
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+
90+
### `cache_has_key(key)`
91+
92+
[method_haskey]: #cachehaskeykey
93+
94+
Checks whether the cache has a value for a given key yet. Returns `true` or `false`.
95+
96+
### `cached_entries()`
97+
98+
[method_allcached]: #cachedentries
99+
100+
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).
101+
102+
### `cached_file_data(path) {|content| ...}`
103+
104+
[method_cached_file]: #cachedfiledatapath-content-
105+
106+
> **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+
108+
For best performance, use this method to read files in Hiera backends.
109+
110+
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:
111+
112+
``` ruby
113+
context.cached_file_data(path) do |content|
114+
begin
115+
JSON.parse(content)
116+
rescue JSON::ParserError => ex
117+
# Filename not included in message, so we add it here.
118+
raise Puppet::DataBinding::LookupError, "Unable to parse (#{path}): #{ex.message}"
119+
end
120+
end
121+
```
122+
123+
On repeated access to a given file, Hiera checks whether the file has changed on disk. If it hasn't, Hiera uses cached data instead of reading and parsing the file again.
124+
125+
This method **does not** use the same per-data-source caches as `cache(key, value)` and friends. It uses a separate cache that lasts across multiple catalog compilations, and is tied to [Puppet Server's environment cache]({{puppetserver}}/admin-api/v1/environment-cache.html).
126+
127+
Since the cache can outlive a given node's catalog compilation, do not do any node-specific pre-processing (like calling `context.interpolate`) in this method's block.
128+
129+
### `explain() { 'message' }`
130+
131+
[method_explain]: #explain--message-
132+
133+
> **Note:** The header above uses Ruby's block syntax. To call this method in the Puppet language, you would use `explain() || { 'message' }`. In both cases, the provided block must take zero arguments.
134+
135+
Adds a message, which appears in debug messages or when using `puppet lookup --explain`. The block provided to this function must return a string.
136+
137+
This is meant for complex lookups where a function tries several different things before arriving at the value. Note that the built-in backends don't use the `explain` method, and they still have relatively verbose explanations; this is for when you need to go above and beyond that.
138+
139+
Feel free to not worry about performance when constructing your message; Hiera never executes the explain block unless debugging is enabled.
140+
141+
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
### The options hash
2+
3+
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.
4+
5+
The options hash contains the following keys:
6+
7+
* `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+
> **Note:** If your backend uses data files, use the context object's [`cached_file_data` method][method_cached_file] to read them.
10+
* `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+
* 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+
For example: this hierarchy level in hiera.yaml...
14+
15+
``` yaml
16+
- name: "Secret data: per-node, per-datacenter, common"
17+
lookup_key: eyaml_lookup_key # eyaml backend
18+
datadir: data
19+
paths:
20+
- "secrets/nodes/%{trusted.certname}.eyaml"
21+
- "secrets/location/%{facts.whereami}.eyaml"
22+
- "common.eyaml"
23+
options:
24+
pkcs7_private_key: /etc/puppetlabs/puppet/eyaml/private_key.pkcs7.pem
25+
pkcs7_public_key: /etc/puppetlabs/puppet/eyaml/public_key.pkcs7.pem
26+
```
27+
28+
...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:
29+
30+
``` ruby
31+
{
32+
'path' => '/etc/puppetlabs/code/environments/production/data/secrets/nodes/web01.example.com.eyaml',
33+
'pkcs7_private_key' => '/etc/puppetlabs/puppet/eyaml/private_key.pkcs7.pem',
34+
'pkcs7_public_key' => '/etc/puppetlabs/puppet/eyaml/public_key.pkcs7.pem'
35+
}
36+
```
37+
38+
In your function's signature, you can validate the options hash by using [the Struct data type](./lang_data_abstract.html#struct) to restrict its contents. In particular, note that you can disable all of the `path` and `glob` settings for your backend by disallowing the `path` key in the options hash.
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
Function names generally resemble these examples:
2+
3+
- `num2bool` (a function that could come from anywhere)
4+
- `postgresql::acls_to_resource_hash` (a function in the `postgresql` module)
5+
- `environment::hash_from_api_call` (a function in an environment)
6+
7+
Function names are almost the same as [class names](./lang_reserved.html#classes-and-defined-resource-types). They consist of one or more segments. Each segment must start with a lowercase letter, and can include:
8+
9+
- Lowercase letters
10+
- Numbers
11+
- Underscores
12+
13+
If a name has multiple segments, they are separated by the double-colon (`::`) namespace separator.
14+
15+
In other words, each segment should match this regular expression:
16+
17+
\A[a-z][a-z0-9_]*\Z
18+
19+
The full name should match this regular expression:
20+
21+
\A([a-z][a-z0-9_]*)(::[a-z][a-z0-9_]*)*\Z
22+
23+
Function names can be either _global_ or _namespaced._
24+
25+
- Global names have only one segment (like `str2bool`), and can be used in any module or environment.
26+
27+
Global names are shorter, but they're not guaranteed to be unique --- two modules might use the same function name, in which case Puppet won't necessarily load the one you want.
28+
- Namespaced names have multiple segments (like `stdlib::str2bool`), and are guaranteed to be unique. The first segment is dictated by the function's location:
29+
- In an environment, it must be the literal word `environment` (like `environment::str2bool`).
30+
- In a module, it must be the module's name (like `stdlib::str2bool`, for a function stored in the `stdlib` module).
31+
32+
Most functions have two name segments, although it's legal to use more.
33+
34+
Some illegal function names:
35+
36+
- `6_pack` (must start with a letter)
37+
- `_hash_from_api_call` (must start with a letter)
38+
- `Find-Resource` (can only contain lowercase letters, numbers, and underscores)
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[node_name_fact]: ./configuration.html#nodenamefact
2+
[node_name_value]: ./configuration.html#nodenamevalue
3+
4+
> #### Note on Non-Certname Node Names
5+
>
6+
> 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+
>
8+
> Setting a non-certname node name is **not officially supported** in Puppet Enterprise.

0 commit comments

Comments
 (0)