puppet 4.3.1-x64-mingw32 → 4.3.2-x64-mingw32
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of puppet might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/ext/build_defaults.yaml +1 -1
- data/lib/hiera/scope.rb +1 -1
- data/lib/puppet/application/lookup.rb +41 -43
- data/lib/puppet/data_providers/lookup_adapter.rb +73 -26
- data/lib/puppet/functions/lookup.rb +126 -150
- data/lib/puppet/functions/match.rb +1 -0
- data/lib/puppet/indirector/hiera.rb +3 -1
- data/lib/puppet/indirector/indirection.rb +6 -2
- data/lib/puppet/indirector/json.rb +2 -2
- data/lib/puppet/module.rb +3 -2
- data/lib/puppet/node.rb +11 -2
- data/lib/puppet/parser/compiler.rb +1 -8
- data/lib/puppet/parser/functions/lookup.rb +128 -149
- data/lib/puppet/parser/functions/match.rb +1 -0
- data/lib/puppet/plugins/data_providers/data_provider.rb +3 -2
- data/lib/puppet/pops/adapters.rb +43 -0
- data/lib/puppet/pops/evaluator/access_operator.rb +3 -3
- data/lib/puppet/pops/evaluator/closure.rb +51 -51
- data/lib/puppet/pops/evaluator/collector_transformer.rb +16 -0
- data/lib/puppet/pops/evaluator/runtime3_support.rb +11 -2
- data/lib/puppet/pops/functions/function.rb +6 -2
- data/lib/puppet/pops/issues.rb +16 -0
- data/lib/puppet/pops/loader/puppet_function_instantiator.rb +3 -2
- data/lib/puppet/pops/lookup.rb +3 -0
- data/lib/puppet/pops/lookup/explainer.rb +73 -3
- data/lib/puppet/pops/lookup/invocation.rb +21 -19
- data/lib/puppet/pops/model/factory.rb +153 -155
- data/lib/puppet/pops/model/model.rb +9 -0
- data/lib/puppet/pops/model/model_label_provider.rb +1 -0
- data/lib/puppet/pops/parser/evaluating_parser.rb +3 -3
- data/lib/puppet/pops/parser/lexer2.rb +411 -393
- data/lib/puppet/pops/parser/slurp_support.rb +5 -1
- data/lib/puppet/pops/types/type_calculator.rb +2 -6
- data/lib/puppet/pops/types/types.rb +3 -9
- data/lib/puppet/pops/validation/checker4_0.rb +36 -12
- data/lib/puppet/provider/group/windows_adsi.rb +2 -2
- data/lib/puppet/provider/package/pip.rb +11 -1
- data/lib/puppet/provider/package/rpm.rb +0 -1
- data/lib/puppet/provider/package/yum.rb +1 -1
- data/lib/puppet/provider/service/debian.rb +5 -18
- data/lib/puppet/provider/service/init.rb +7 -0
- data/lib/puppet/provider/service/launchd.rb +6 -0
- data/lib/puppet/provider/service/systemd.rb +1 -1
- data/lib/puppet/provider/user/windows_adsi.rb +2 -2
- data/lib/puppet/provider/yumrepo/inifile.rb +6 -3
- data/lib/puppet/resource/type.rb +2 -1
- data/lib/puppet/transaction/additional_resource_generator.rb +17 -3
- data/lib/puppet/type/group.rb +6 -2
- data/lib/puppet/util/windows.rb +4 -0
- data/lib/puppet/util/windows/adsi.rb +61 -24
- data/lib/puppet/util/windows/principal.rb +181 -0
- data/lib/puppet/util/windows/registry.rb +21 -15
- data/lib/puppet/util/windows/sid.rb +42 -11
- data/lib/puppet/version.rb +1 -1
- data/spec/fixtures/unit/application/environments/production/data/common.yaml +4 -0
- data/spec/fixtures/unit/application/environments/production/manifests/site.pp +1 -0
- data/spec/fixtures/unit/application/environments/puppet_func_provider/environment.conf +1 -0
- data/spec/fixtures/unit/application/environments/puppet_func_provider/functions/data.pp +10 -0
- data/spec/fixtures/unit/application/environments/puppet_func_provider/manifests/site.pp +1 -0
- data/spec/fixtures/unit/data_providers/environments/hiera_module_config/data/common.yaml +4 -0
- data/spec/fixtures/unit/data_providers/environments/hiera_module_config/data/specific.yaml +4 -0
- data/spec/fixtures/unit/data_providers/environments/hiera_module_config/hiera.yaml +7 -0
- data/spec/fixtures/unit/data_providers/environments/hiera_modules/data/common.yaml +4 -0
- data/spec/fixtures/unit/data_providers/environments/hiera_modules/data/specific.yaml +4 -0
- data/spec/fixtures/unit/data_providers/environments/hiera_modules/environment.conf +2 -0
- data/spec/fixtures/unit/data_providers/environments/hiera_modules/hiera.yaml +7 -0
- data/spec/fixtures/unit/data_providers/environments/hiera_modules/manifests/site.pp +1 -0
- data/spec/fixtures/unit/data_providers/environments/hiera_modules/modules/one/data/common.yaml +6 -0
- data/spec/fixtures/unit/data_providers/environments/hiera_modules/modules/one/hiera.yaml +5 -0
- data/spec/fixtures/unit/data_providers/environments/hiera_modules/modules/one/manifests/init.pp +2 -0
- data/spec/fixtures/unit/data_providers/environments/hiera_modules/modules/one/metadata.json +9 -0
- data/spec/fixtures/unit/data_providers/environments/hiera_modules/modules/two/data/common.yaml +4 -0
- data/spec/fixtures/unit/data_providers/environments/hiera_modules/modules/two/hiera.yaml +5 -0
- data/spec/fixtures/unit/data_providers/environments/hiera_modules/modules/two/manifests/init.pp +3 -0
- data/spec/fixtures/unit/data_providers/environments/hiera_modules/modules/two/metadata.json +9 -0
- data/spec/fixtures/unit/pops/loaders/loaders/dependent_modules_with_metadata/modules/usee/functions/usee_puppet.pp +3 -0
- data/spec/fixtures/unit/pops/loaders/loaders/dependent_modules_with_metadata/{usee → modules/usee}/lib/puppet/functions/usee/callee.rb +0 -0
- data/spec/fixtures/unit/pops/loaders/loaders/dependent_modules_with_metadata/modules/usee/lib/puppet/functions/usee/usee_ruby.rb +6 -0
- data/spec/fixtures/unit/pops/loaders/loaders/dependent_modules_with_metadata/modules/usee/manifests/init.pp +6 -0
- data/spec/fixtures/unit/pops/loaders/loaders/dependent_modules_with_metadata/modules/usee2/lib/puppet/functions/usee2/callee.rb +5 -0
- data/spec/fixtures/unit/pops/loaders/loaders/dependent_modules_with_metadata/modules/user/functions/puppet_calling_puppet.pp +5 -0
- data/spec/fixtures/unit/pops/loaders/loaders/dependent_modules_with_metadata/modules/user/functions/puppet_calling_puppet_init.pp +5 -0
- data/spec/fixtures/unit/pops/loaders/loaders/dependent_modules_with_metadata/modules/user/functions/puppet_calling_ruby.pp +5 -0
- data/spec/fixtures/unit/pops/loaders/loaders/dependent_modules_with_metadata/{user → modules/user}/lib/puppet/functions/user/caller.rb +0 -0
- data/spec/fixtures/unit/pops/loaders/loaders/dependent_modules_with_metadata/modules/user/lib/puppet/functions/user/caller2.rb +5 -0
- data/spec/fixtures/unit/pops/loaders/loaders/dependent_modules_with_metadata/modules/user/lib/puppet/functions/user/ruby_calling_puppet.rb +5 -0
- data/spec/fixtures/unit/pops/loaders/loaders/dependent_modules_with_metadata/modules/user/lib/puppet/functions/user/ruby_calling_puppet_init.rb +5 -0
- data/spec/fixtures/unit/pops/loaders/loaders/dependent_modules_with_metadata/modules/user/lib/puppet/functions/user/ruby_calling_ruby.rb +5 -0
- data/spec/fixtures/unit/pops/loaders/loaders/dependent_modules_with_metadata/modules/user/manifests/init.pp +81 -0
- data/spec/fixtures/unit/pops/loaders/loaders/dependent_modules_with_metadata/{user → modules/user}/metadata.json +2 -1
- data/spec/integration/parser/collection_spec.rb +8 -0
- data/spec/integration/util/windows/principal_spec.rb +115 -0
- data/spec/{unit → integration}/util/windows/registry_spec.rb +91 -1
- data/spec/integration/util/windows/security_spec.rb +2 -2
- data/spec/unit/application/lookup_spec.rb +138 -28
- data/spec/unit/data_providers/hiera_data_provider_spec.rb +182 -5
- data/spec/unit/face/epp_face_spec.rb +2 -2
- data/spec/unit/functions/epp_spec.rb +6 -6
- data/spec/unit/functions/inline_epp_spec.rb +4 -4
- data/spec/unit/functions/lookup_spec.rb +30 -3
- data/spec/unit/functions4_spec.rb +1 -1
- data/spec/unit/hiera/scope_spec.rb +5 -2
- data/spec/unit/indirector/json_spec.rb +1 -1
- data/spec/unit/node_spec.rb +8 -0
- data/spec/unit/parser/compiler_spec.rb +0 -18
- data/spec/unit/pops/evaluator/access_ops_spec.rb +4 -4
- data/spec/unit/pops/evaluator/evaluating_parser_spec.rb +1 -1
- data/spec/unit/pops/loaders/loaders_spec.rb +84 -2
- data/spec/unit/pops/parser/lexer2_spec.rb +6 -0
- data/spec/unit/pops/parser/parser_rspec_helper.rb +5 -0
- data/spec/unit/pops/types/type_calculator_spec.rb +0 -17
- data/spec/unit/pops/validator/validator_spec.rb +87 -0
- data/spec/unit/provider/group/windows_adsi_spec.rb +8 -8
- data/spec/unit/provider/package/pip_spec.rb +41 -13
- data/spec/unit/provider/package/rpm_spec.rb +2 -25
- data/spec/unit/provider/package/yum_spec.rb +1 -1
- data/spec/unit/provider/service/debian_spec.rb +6 -24
- data/spec/unit/provider/service/init_spec.rb +11 -1
- data/spec/unit/provider/service/launchd_spec.rb +11 -0
- data/spec/unit/provider/service/systemd_spec.rb +18 -12
- data/spec/unit/provider/service/upstart_spec.rb +57 -0
- data/spec/unit/provider/user/windows_adsi_spec.rb +5 -5
- data/spec/unit/provider/yumrepo/inifile_spec.rb +16 -0
- data/spec/unit/resource_spec.rb +12 -2
- data/spec/unit/util/windows/adsi_spec.rb +44 -36
- data/spec/unit/util/windows/sid_spec.rb +47 -10
- metadata +77 -10
@@ -23,7 +23,9 @@ class Puppet::Indirector::Hiera < Puppet::Indirector::Terminus
|
|
23
23
|
throw :no_such_key if value.equal?(not_found)
|
24
24
|
value
|
25
25
|
rescue *DataBindingExceptions => detail
|
26
|
-
|
26
|
+
error = Puppet::DataBinding::LookupError.new("DataBinding 'hiera': #{detail.message}")
|
27
|
+
error.set_backtrace(detail.backtrace)
|
28
|
+
raise error
|
27
29
|
end
|
28
30
|
|
29
31
|
private
|
@@ -207,10 +207,14 @@ class Puppet::Indirector::Indirection
|
|
207
207
|
filtered = result
|
208
208
|
if terminus.respond_to?(:filter)
|
209
209
|
Puppet::Util::Profiler.profile("Filtered result for #{self.name} #{request.key}", [:indirector, :filter, self.name, request.key]) do
|
210
|
-
|
210
|
+
begin
|
211
|
+
filtered = terminus.filter(result)
|
212
|
+
rescue Puppet::Error => detail
|
213
|
+
Puppet.log_exception(detail)
|
214
|
+
raise detail
|
215
|
+
end
|
211
216
|
end
|
212
217
|
end
|
213
|
-
|
214
218
|
filtered
|
215
219
|
end
|
216
220
|
end
|
@@ -15,7 +15,7 @@ class Puppet::Indirector::JSON < Puppet::Indirector::Terminus
|
|
15
15
|
filename = path(request.key)
|
16
16
|
FileUtils.mkdir_p(File.dirname(filename))
|
17
17
|
|
18
|
-
Puppet::Util.replace_file(filename, 0660) {|f| f.print to_json(request.instance) }
|
18
|
+
Puppet::Util.replace_file(filename, 0660) {|f| f.print to_json(request.instance).force_encoding(Encoding::ASCII_8BIT) }
|
19
19
|
rescue TypeError => detail
|
20
20
|
Puppet.log_exception(detail, "Could not save #{self.name} #{request.key}: #{detail}")
|
21
21
|
end
|
@@ -52,7 +52,7 @@ class Puppet::Indirector::JSON < Puppet::Indirector::Terminus
|
|
52
52
|
json = nil
|
53
53
|
|
54
54
|
begin
|
55
|
-
json =
|
55
|
+
json = Puppet::FileSystem.read(file).force_encoding(Encoding::ASCII_8BIT)
|
56
56
|
rescue Errno::ENOENT
|
57
57
|
return nil
|
58
58
|
rescue => detail
|
data/lib/puppet/module.rb
CHANGED
@@ -155,6 +155,8 @@ class Puppet::Module
|
|
155
155
|
|
156
156
|
if attr == :dependencies
|
157
157
|
value.each do |dep|
|
158
|
+
name = dep['name']
|
159
|
+
dep['name'] = name.tr('-', '/') unless name.nil?
|
158
160
|
dep['version_requirement'] ||= '>= 0.0.0'
|
159
161
|
end
|
160
162
|
end
|
@@ -269,11 +271,10 @@ class Puppet::Module
|
|
269
271
|
|
270
272
|
dependencies.each do |dependency|
|
271
273
|
name = dependency['name']
|
272
|
-
forge_name = name.tr('-', '/')
|
273
274
|
version_string = dependency['version_requirement'] || '>= 0.0.0'
|
274
275
|
|
275
276
|
dep_mod = begin
|
276
|
-
environment.module_by_forge_name(
|
277
|
+
environment.module_by_forge_name(name)
|
277
278
|
rescue
|
278
279
|
nil
|
279
280
|
end
|
data/lib/puppet/node.rb
CHANGED
@@ -21,6 +21,8 @@ class Puppet::Node
|
|
21
21
|
|
22
22
|
attr_reader :server_facts
|
23
23
|
|
24
|
+
ENVIRONMENT = 'environment'.freeze
|
25
|
+
|
24
26
|
def initialize_from_hash(data)
|
25
27
|
@name = data['name'] || (raise ArgumentError, "No name provided in serialized data")
|
26
28
|
@classes = data['classes'] || []
|
@@ -48,7 +50,7 @@ class Puppet::Node
|
|
48
50
|
if @environment
|
49
51
|
@environment
|
50
52
|
else
|
51
|
-
if env = parameters[
|
53
|
+
if env = parameters[ENVIRONMENT]
|
52
54
|
self.environment = env
|
53
55
|
elsif environment_name
|
54
56
|
self.environment = environment_name
|
@@ -70,6 +72,13 @@ class Puppet::Node
|
|
70
72
|
else
|
71
73
|
@environment = env
|
72
74
|
end
|
75
|
+
|
76
|
+
# Keep environment_name attribute and parameter in sync if they have been set
|
77
|
+
unless @environment.nil?
|
78
|
+
@parameters[ENVIRONMENT] = @environment.name if @parameters.include?(ENVIRONMENT)
|
79
|
+
self.environment_name = @environment.name if instance_variable_defined?(:@environment_name)
|
80
|
+
end
|
81
|
+
@environment
|
73
82
|
end
|
74
83
|
|
75
84
|
def has_environment_instance?
|
@@ -125,7 +134,7 @@ class Puppet::Node
|
|
125
134
|
end
|
126
135
|
end
|
127
136
|
|
128
|
-
@parameters[
|
137
|
+
@parameters[ENVIRONMENT] ||= self.environment.name.to_s
|
129
138
|
end
|
130
139
|
|
131
140
|
def add_server_facts(facts)
|
@@ -803,14 +803,7 @@ class Puppet::Parser::Compiler
|
|
803
803
|
if trusted_param
|
804
804
|
# Blows up if it is a parameter as it will be set as $trusted by the compiler as if it was a variable
|
805
805
|
node.parameters.delete('trusted')
|
806
|
-
|
807
|
-
# looks like a hash of trusted data - resurrect it
|
808
|
-
# Allow root to trust the authenticated information if option --trusted is given
|
809
|
-
if !Puppet.features.root?
|
810
|
-
# Set as not trusted - but keep the information
|
811
|
-
trusted_param['authenticated'] = false
|
812
|
-
end
|
813
|
-
else
|
806
|
+
unless trusted_param.is_a?(Hash) && %w{authenticated certname extensions}.all? {|key| trusted_param.has_key?(key) }
|
814
807
|
# trusted is some kind of garbage, do not resurrect
|
815
808
|
trusted_param = nil
|
816
809
|
end
|
@@ -1,154 +1,133 @@
|
|
1
1
|
Puppet::Parser::Functions.newfunction(:lookup, :type => :rvalue, :arity => -2, :doc => <<-'ENDHEREDOC') do |args|
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
lookup
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
`
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
2
|
+
Uses the Puppet lookup system to retrieve a value for a given key. By default,
|
3
|
+
this returns the first value found (and fails compilation if no values are
|
4
|
+
available), but you can configure it to merge multiple values into one, fail
|
5
|
+
gracefully, and more.
|
6
|
+
|
7
|
+
When looking up a key, Puppet will search up to three tiers of data, in the
|
8
|
+
following order:
|
9
|
+
|
10
|
+
1. Hiera.
|
11
|
+
2. The current environment's data provider.
|
12
|
+
3. The indicated module's data provider, if the key is of the form
|
13
|
+
`<MODULE NAME>::<SOMETHING>`.
|
14
|
+
|
15
|
+
#### Arguments
|
16
|
+
|
17
|
+
You must provide the name of a key to look up, and can optionally provide other
|
18
|
+
arguments. You can combine these arguments in the following ways:
|
19
|
+
|
20
|
+
* `lookup( <NAME>, [<VALUE TYPE>], [<MERGE BEHAVIOR>], [<DEFAULT VALUE>] )`
|
21
|
+
* `lookup( [<NAME>], <OPTIONS HASH> )`
|
22
|
+
* `lookup( as above ) |$key| { # lambda returns a default value }`
|
23
|
+
|
24
|
+
Arguments in `[square brackets]` are optional.
|
25
|
+
|
26
|
+
The arguments accepted by `lookup` are as follows:
|
27
|
+
|
28
|
+
1. `<NAME>` (string or array) --- The name of the key to look up.
|
29
|
+
* This can also be an array of keys. If Puppet doesn't find anything for the
|
30
|
+
first key, it will try again with the subsequent ones, only resorting to a
|
31
|
+
default value if none of them succeed.
|
32
|
+
2. `<VALUE TYPE>` (data type) --- A
|
33
|
+
[data type](https://docs.puppetlabs.com/puppet/latest/reference/lang_data_type.html)
|
34
|
+
that must match the retrieved value; if not, the lookup (and catalog
|
35
|
+
compilation) will fail. Defaults to `Data` (accepts any normal value).
|
36
|
+
3. `<MERGE BEHAVIOR>` (string or hash; see **"Merge Behaviors"** below) ---
|
37
|
+
Whether (and how) to combine multiple values. If present, this overrides any
|
38
|
+
merge behavior specified in the data sources. Defaults to no value; Puppet will
|
39
|
+
use merge behavior from the data sources if present, and will otherwise do a
|
40
|
+
first-found lookup.
|
41
|
+
4. `<DEFAULT VALUE>` (any normal value) --- If present, `lookup` returns this
|
42
|
+
when it can't find a normal value. Default values are never merged with found
|
43
|
+
values. Like a normal value, the default must match the value type. Defaults to
|
44
|
+
no value; if Puppet can't find a normal value, the lookup (and compilation) will
|
45
|
+
fail.
|
46
|
+
5. `<OPTIONS HASH>` (hash) --- Alternate way to set the arguments above, plus
|
47
|
+
some less-common extra options. If you pass an options hash, you can't combine
|
48
|
+
it with any regular arguments (except `<NAME>`). An options hash can have the
|
49
|
+
following keys:
|
50
|
+
* `'name'` --- Same as `<NAME>` (argument 1). You can pass this as an
|
51
|
+
argument or in the hash, but not both.
|
52
|
+
* `'value_type'` --- Same as `<VALUE TYPE>` (argument 2).
|
53
|
+
* `'merge'` --- Same as `<MERGE BEHAVIOR>` (argument 3).
|
54
|
+
* `'default_value'` --- Same as `<DEFAULT VALUE>` (argument 4).
|
55
|
+
* `'default_values_hash'` (hash) --- A hash of lookup keys and default
|
56
|
+
values. If Puppet can't find a normal value, it will check this hash for the
|
57
|
+
requested key before giving up. You can combine this with `default_value` or
|
58
|
+
a lambda, which will be used if the key isn't present in this hash. Defaults
|
59
|
+
to an empty hash.
|
60
|
+
* `'override'` (hash) --- A hash of lookup keys and override values. Puppet
|
61
|
+
will check for the requested key in the overrides hash _first;_ if found, it
|
62
|
+
returns that value as the _final_ value, ignoring merge behavior. Defaults
|
63
|
+
to an empty hash.
|
64
|
+
|
65
|
+
Finally, `lookup` can take a lambda, which must accept a single parameter.
|
66
|
+
This is yet another way to set a default value for the lookup; if no results are
|
67
|
+
found, Puppet will pass the requested key to the lambda and use its result as
|
68
|
+
the default value.
|
69
|
+
|
70
|
+
#### Merge Behaviors
|
71
|
+
|
72
|
+
Puppet lookup uses a hierarchy of data sources, and a given key might have
|
73
|
+
values in multiple sources. By default, Puppet returns the first value it finds,
|
74
|
+
but it can also continue searching and merge all the values together.
|
75
|
+
|
76
|
+
> **Note:** Data sources can use the special `lookup_options` metadata key to
|
77
|
+
request a specific merge behavior for a key. The `lookup` function will use that
|
78
|
+
requested behavior unless you explicitly specify one.
|
79
|
+
|
80
|
+
The valid merge behaviors are:
|
81
|
+
|
82
|
+
* `'first'` --- Returns the first value found, with no merging. Puppet lookup's
|
83
|
+
default behavior.
|
84
|
+
* `'unique'` (called "array merge" in classic Hiera) --- Combines any number of
|
85
|
+
arrays and scalar values to return a merged, flattened array with all duplicate
|
86
|
+
values removed. The lookup will fail if any hash values are found.
|
87
|
+
* `'hash'` --- Combines the keys and values of any number of hashes to return a
|
88
|
+
merged hash. If the same key exists in multiple source hashes, Puppet will use
|
89
|
+
the value from the highest-priority data source; it won't recursively merge the
|
90
|
+
values.
|
91
|
+
* `'deep'` --- Combines the keys and values of any number of hashes to return a
|
92
|
+
merged hash. If the same key exists in multiple source hashes, Puppet will
|
93
|
+
recursively merge hash or array values (with duplicate values removed from
|
94
|
+
arrays). For conflicting scalar values, the highest-priority value will win.
|
95
|
+
* `{'strategy' => 'first|unique|hash'}` --- Same as the string versions of these
|
96
|
+
merge behaviors.
|
97
|
+
* `{'strategy' => 'deep', <DEEP OPTION> => <VALUE>, ...}` --- Same as `'deep'`,
|
98
|
+
but can adjust the merge with additional options. The available options are:
|
99
|
+
* `'knockout_prefix'` (string or undef) --- A string prefix to indicate a
|
100
|
+
value should be _removed_ from the final result. Defaults to `undef`, which
|
101
|
+
disables this feature.
|
102
|
+
* `'sort_merged_arrays'` (boolean) --- Whether to sort all arrays that are
|
103
|
+
merged together. Defaults to `false`.
|
104
|
+
* `'unpack_arrays'` (string or undef) --- A delimiter string; Puppet will
|
105
|
+
join merged arrays with this delimiter, then split them again. Defaults to
|
106
|
+
`undef`, which disables this feature.
|
107
|
+
* `'merge_hash_arrays'` (boolean) --- Whether to merge hashes within arrays.
|
108
|
+
Defaults to `false`.
|
109
|
+
|
110
|
+
#### Examples
|
111
|
+
|
112
|
+
Look up a key and return the first value found:
|
113
|
+
|
114
|
+
lookup('ntp::service_name')
|
115
|
+
|
116
|
+
Do a unique merge lookup of class names, then add all of those classes to the
|
117
|
+
catalog (like `hiera_include`):
|
118
|
+
|
119
|
+
lookup('classes', Array[String], 'unique').include
|
120
|
+
|
121
|
+
Do a deep hash merge lookup of user data, but let higher priority sources
|
122
|
+
remove values by prefixing them with `--`:
|
123
|
+
|
124
|
+
lookup( { 'name' => 'users',
|
125
|
+
'merge' => {
|
126
|
+
'strategy' => 'deep',
|
127
|
+
'knockout_prefix' => '--',
|
128
|
+
},
|
129
|
+
})
|
106
130
|
|
107
|
-
The produced value is subject to type validation using the `value_type` (if given) and an error is raised unless
|
108
|
-
the resulting value is of correct type.
|
109
|
-
|
110
|
-
*Examples*
|
111
|
-
|
112
|
-
When called with one argument; **the name**, it
|
113
|
-
returns the bound value with the given name after having asserted it has the default datatype `Data`:
|
114
|
-
|
115
|
-
lookup('the_name')
|
116
|
-
|
117
|
-
When called with two arguments; **the name**, and **the expected type**, it
|
118
|
-
returns the bound value with the given name after having asserted it has the given data
|
119
|
-
type ('String' in the example):
|
120
|
-
|
121
|
-
lookup('the_name', String)
|
122
|
-
|
123
|
-
When called with four arguments, **the name**, the **expected type**, the **merge** strategy, and a
|
124
|
-
**default value**, it returns the bound value with the given name, or the default after having asserted the value
|
125
|
-
has the given data type:
|
126
|
-
|
127
|
-
lookup('the_name', String, undef, 'Fred')
|
128
|
-
lookup('the_name', Array[String], 'unique', [Fred])
|
129
|
-
|
130
|
-
Using a lambda to provide a default value by calling a function:
|
131
|
-
|
132
|
-
lookup('the_size', Integer[1,100]) |$name| {
|
133
|
-
obtain_size_default()
|
134
|
-
}
|
135
|
-
|
136
|
-
There are two ways to make lookup return undef when no matching key was found instead of raising an error.
|
137
|
-
Either call it with four arguments (the `merge` argument must be present even when using the default strategy
|
138
|
-
to ensure that the four argument variant is used):
|
139
|
-
|
140
|
-
$are_you_there = lookup('peekaboo', Optional[String], undef, undef)
|
141
|
-
|
142
|
-
or call it using an options hash:
|
143
|
-
|
144
|
-
$are_you_there = lookup('peekaboo', { 'default_value' => undef })
|
145
|
-
$are_you_there = lookup({ 'name' => 'peekaboo', 'default_value' => undef })
|
146
|
-
|
147
|
-
or with a block that produces an undef value:
|
148
|
-
|
149
|
-
$are_you_there = lookup('peekaboo', Optional[String]) |$name| { undef }
|
150
|
-
|
151
|
-
- Since 4.0.0
|
152
131
|
ENDHEREDOC
|
153
132
|
function_fail(["lookup() has been converted to 4x API"])
|
154
133
|
end
|
@@ -98,6 +98,7 @@ module Puppet::Plugins::DataProviders
|
|
98
98
|
end
|
99
99
|
|
100
100
|
class ModuleDataProvider
|
101
|
+
LOOKUP_OPTIONS = Puppet::Pops::Lookup::LOOKUP_OPTIONS
|
101
102
|
include DataProvider
|
102
103
|
|
103
104
|
# Retrieve the first segment of the qualified name _key_. This method will throw
|
@@ -106,7 +107,7 @@ module Puppet::Plugins::DataProviders
|
|
106
107
|
# @param key [String] The key
|
107
108
|
# @return [String] The first segment of the given key
|
108
109
|
def data_key(key, lookup_invocation)
|
109
|
-
return lookup_invocation.module_name if key ==
|
110
|
+
return lookup_invocation.module_name if key == LOOKUP_OPTIONS
|
110
111
|
qual_index = key.index('::')
|
111
112
|
throw :no_such_key if qual_index.nil?
|
112
113
|
key[0..qual_index-1]
|
@@ -121,7 +122,7 @@ module Puppet::Plugins::DataProviders
|
|
121
122
|
def validate_data(data, module_name)
|
122
123
|
module_prefix = "#{module_name}::"
|
123
124
|
data.each_key do |k|
|
124
|
-
unless k.is_a?(String) && (k ==
|
125
|
+
unless k.is_a?(String) && (k == LOOKUP_OPTIONS || k.start_with?(module_prefix))
|
125
126
|
raise Puppet::DataBinding::LookupError, "Module data for module '#{module_name}' must use keys qualified with the name of the module"
|
126
127
|
end
|
127
128
|
end
|