puppet 4.2.0 → 4.2.1

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.

Files changed (77) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +1 -1
  3. data/ext/project_data.yaml +1 -1
  4. data/ext/suse/client.init +23 -10
  5. data/lib/hiera/puppet_function.rb +5 -5
  6. data/lib/puppet/application/agent.rb +14 -4
  7. data/lib/puppet/application/apply.rb +13 -4
  8. data/lib/puppet/defaults.rb +1 -1
  9. data/lib/puppet/environments.rb +85 -5
  10. data/lib/puppet/functions/epp.rb +29 -37
  11. data/lib/puppet/functions/hiera_include.rb +2 -2
  12. data/lib/puppet/functions/inline_epp.rb +44 -71
  13. data/lib/puppet/module_tool/applications/unpacker.rb +1 -1
  14. data/lib/puppet/module_tool/skeleton/templates/generator/manifests/init.pp.erb +25 -18
  15. data/lib/puppet/node.rb +11 -5
  16. data/lib/puppet/parser/functions/epp.rb +29 -37
  17. data/lib/puppet/parser/functions/inline_epp.rb +35 -60
  18. data/lib/puppet/pops/issues.rb +6 -2
  19. data/lib/puppet/pops/patterns.rb +3 -0
  20. data/lib/puppet/pops/types/type_parser.rb +2 -2
  21. data/lib/puppet/pops/validation/checker4_0.rb +4 -0
  22. data/lib/puppet/provider/zone/solaris.rb +2 -2
  23. data/lib/puppet/type.rb +4 -4
  24. data/lib/puppet/util.rb +9 -1
  25. data/lib/puppet/util/command_line.rb +4 -0
  26. data/lib/puppet/version.rb +1 -1
  27. data/spec/integration/parser/compiler_spec.rb +7 -5
  28. data/spec/integration/provider/package_spec.rb +3 -1
  29. data/spec/integration/ssl/certificate_authority_spec.rb +0 -1
  30. data/spec/integration/ssl/certificate_request_spec.rb +0 -1
  31. data/spec/integration/ssl/certificate_revocation_list_spec.rb +0 -1
  32. data/spec/integration/ssl/host_spec.rb +0 -1
  33. data/spec/integration/util/rdoc/parser_spec.rb +1 -1
  34. data/spec/unit/application/apply_spec.rb +1 -1
  35. data/spec/unit/application/filebucket_spec.rb +1 -1
  36. data/spec/unit/application_spec.rb +3 -3
  37. data/spec/unit/environments_spec.rb +2 -0
  38. data/spec/unit/face/node_spec.rb +1 -1
  39. data/spec/unit/file_serving/configuration_spec.rb +1 -1
  40. data/spec/unit/functions/hiera_spec.rb +2 -2
  41. data/spec/unit/graph/sequential_prioritizer_spec.rb +1 -1
  42. data/spec/unit/indirector/indirection_spec.rb +2 -2
  43. data/spec/unit/indirector/ssl_file_spec.rb +1 -1
  44. data/spec/unit/indirector/yaml_spec.rb +1 -1
  45. data/spec/unit/module_tool/application_spec.rb +1 -1
  46. data/spec/unit/module_tool/applications/builder_spec.rb +1 -1
  47. data/spec/unit/network/authstore_spec.rb +1 -1
  48. data/spec/unit/network/http/compression_spec.rb +1 -1
  49. data/spec/unit/network/http/handler_spec.rb +0 -5
  50. data/spec/unit/network/rights_spec.rb +3 -3
  51. data/spec/unit/node_spec.rb +27 -0
  52. data/spec/unit/parser/ast/leaf_spec.rb +1 -1
  53. data/spec/unit/pops/evaluator/evaluating_parser_spec.rb +1 -0
  54. data/spec/unit/pops/types/type_parser_spec.rb +8 -0
  55. data/spec/unit/pops/validator/validator_spec.rb +19 -0
  56. data/spec/unit/property_spec.rb +1 -1
  57. data/spec/unit/provider/service/debian_spec.rb +1 -0
  58. data/spec/unit/provider/service/gentoo_spec.rb +1 -0
  59. data/spec/unit/provider/service/init_spec.rb +6 -0
  60. data/spec/unit/provider/service/openrc_spec.rb +1 -0
  61. data/spec/unit/provider/service/src_spec.rb +1 -0
  62. data/spec/unit/provider/ssh_authorized_key/parsed_spec.rb +1 -1
  63. data/spec/unit/provider/zone/solaris_spec.rb +19 -0
  64. data/spec/unit/resource_spec.rb +2 -2
  65. data/spec/unit/settings_spec.rb +1 -1
  66. data/spec/unit/ssl/certificate_authority_spec.rb +5 -3
  67. data/spec/unit/ssl/host_spec.rb +2 -2
  68. data/spec/unit/type/host_spec.rb +4 -4
  69. data/spec/unit/type/tidy_spec.rb +4 -4
  70. data/spec/unit/type/vlan_spec.rb +1 -1
  71. data/spec/unit/util/ldap/generator_spec.rb +1 -1
  72. data/spec/unit/util/network_device/cisco/device_spec.rb +1 -1
  73. data/spec/unit/util/network_device/transport/ssh_spec.rb +1 -1
  74. data/spec/unit/util/network_device_spec.rb +1 -1
  75. data/spec/unit/util/storage_spec.rb +5 -1
  76. data/spec/unit/util_spec.rb +21 -2
  77. metadata +3195 -3203
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 8992a4a919d62e657181b071a42be09406a6d707
4
+ data.tar.gz: 6f1b3395bdf1187d079a204aa344229c28ea06a3
5
+ SHA512:
6
+ metadata.gz: 078c55ab6450b165ecf373ff0502b6ca30715fab6cc5d38637559f341d5c3edf88cf6d6563f217dbb32dbfdf37dabca04de45f61013de73071262ad1d9db466c
7
+ data.tar.gz: 5b6f1b6e17a0326eff3e928acb0326c557be5938d46c2bc974eb28a819afbb089aede8ccb5ef1ce4696dd7f0dc9403094e7fab12d0299c92dee0820d59a9fbe5
data/Gemfile CHANGED
@@ -25,7 +25,7 @@ end
25
25
 
26
26
  gem "puppet", :path => File.dirname(__FILE__), :require => false
27
27
  gem "facter", *location_for(ENV['FACTER_LOCATION'] || ['> 2.0', '< 4'])
28
- gem "hiera", *location_for(ENV['HIERA_LOCATION'] || ['>= 2.0', '< 3'])
28
+ gem "hiera", *location_for(ENV['HIERA_LOCATION'] || ['>= 2.0', '< 4'])
29
29
  gem "rake", "10.1.1", :require => false
30
30
 
31
31
  group(:development, :test) do
@@ -16,7 +16,7 @@ gem_default_executables: 'puppet'
16
16
  gem_forge_project: 'puppet'
17
17
  gem_runtime_dependencies:
18
18
  facter: ['> 2.0', '< 4']
19
- hiera: ['>= 2.0', '< 3']
19
+ hiera: ['>= 2.0', '< 4']
20
20
  json_pure:
21
21
  gem_rdoc_options:
22
22
  - --title
@@ -36,7 +36,6 @@
36
36
  lockfile=/var/lock/subsys/puppet
37
37
  pidfile=/var/run/puppetlabs/agent.pid
38
38
  puppetd=/opt/puppetlabs/puppet/bin/puppet
39
- RETVAL=0
40
39
 
41
40
  PUPPET_OPTS="agent"
42
41
 
@@ -63,9 +62,18 @@ case "$1" in
63
62
  ## Start daemon with startproc(8). If this fails
64
63
  ## the echo return value is set appropriate.
65
64
 
66
- # startproc should return 0, even if service is
67
- # already running to match LSB spec.
68
- startproc -p ${pidfile} $puppetd ${PUPPET_OPTS} ${PUPPET_EXTRA_OPTS} && touch ${lockfile}
65
+ ## This accounts for the behavior of startproc on sles 10.
66
+ ## Check to see if a running process matches the contents
67
+ ## of the pidfile, and do nothing if true. Otherwise
68
+ ## force a process start
69
+ if [ -f "${pidfile}" ]; then
70
+ PID=$(cat "$pidfile")
71
+ if [ "$PID" -eq $(pgrep -f "$puppetd") ] ; then
72
+ rc_status -v
73
+ rc_exit
74
+ fi
75
+ fi
76
+ startproc -f -w -p "${pidfile}" "${puppetd}" "${PUPPET_OPTS}" "${PUPPET_EXTRA_OPTS}" && touch "${lockfile}"
69
77
  # Remember status and be verbose
70
78
  rc_status -v
71
79
  ;;
@@ -74,7 +82,7 @@ case "$1" in
74
82
  ## Stop daemon with killproc(8) and if this fails
75
83
  ## set echo the echo return value.
76
84
 
77
- killproc -QUIT -p ${pidfile} $puppetd && rm -f ${lockfile} ${pidfile}
85
+ killproc -QUIT -p "${pidfile}" "${puppetd}" && rm -f "${lockfile}" "${pidfile}"
78
86
 
79
87
  # Remember status and be verbose
80
88
  rc_status -v
@@ -103,7 +111,7 @@ case "$1" in
103
111
 
104
112
  echo -n "Reload service puppet"
105
113
  ## if it supports it:
106
- killproc -HUP -p ${pidfile} $puppetd
114
+ killproc -HUP -p "${pidfile}" "${puppetd}"
107
115
  rc_status -v
108
116
  ;;
109
117
  reload)
@@ -112,7 +120,7 @@ case "$1" in
112
120
 
113
121
  # If it supports signalling:
114
122
  echo -n "Reload puppet services."
115
- killproc -HUP -p ${pidfile} $puppetd
123
+ killproc -HUP -p "${pidfile}" "${puppetd}"
116
124
  rc_status -v
117
125
  ;;
118
126
  status)
@@ -127,12 +135,17 @@ case "$1" in
127
135
  # 3 - service not running
128
136
 
129
137
  # NOTE: checkproc returns LSB compliant status values.
130
- checkproc -p ${pidfile} $puppetd
131
- rc_status -v
138
+ if [ -f "${pidfile}" ]; then
139
+ checkproc -p "${pidfile}" "${puppetd}"
140
+ rc_status -v
141
+ else
142
+ rc_failed 3
143
+ rc_status -v
144
+ fi
132
145
  ;;
133
146
  once)
134
147
  shift
135
- $puppetd ${PUPPET_OPTS} --onetime ${PUPPET_EXTRA_OPTS} $@
148
+ $puppetd "${PUPPET_OPTS}" --onetime "${PUPPET_EXTRA_OPTS}" $@
136
149
  ;;
137
150
  *)
138
151
  echo "Usage: $0 {start|stop|status|try-restart|restart|force-reload|reload|once}"
@@ -43,13 +43,13 @@ class Hiera::PuppetFunction < Puppet::Functions::InternalFunction
43
43
  end
44
44
 
45
45
  def hiera_no_default(scope, key)
46
- post_lookup(key, lookup(scope, key, nil, nil))
46
+ post_lookup(scope, key, lookup(scope, key, nil, nil))
47
47
  end
48
48
 
49
49
  def hiera_with_default(scope, key, default, override = nil)
50
50
  undefined = (@@undefined_value ||= Object.new)
51
51
  result = lookup(scope, key, undefined, override)
52
- post_lookup(key, result.equal?(undefined) ? default : result)
52
+ post_lookup(scope, key, result.equal?(undefined) ? default : result)
53
53
  end
54
54
 
55
55
  def hiera_block1(scope, key, &default_block)
@@ -63,20 +63,20 @@ class Hiera::PuppetFunction < Puppet::Functions::InternalFunction
63
63
  def common(scope, key, override, default_block)
64
64
  undefined = (@@undefined_value ||= Object.new)
65
65
  result = lookup(scope, key, undefined, override)
66
- post_lookup(key, result.equal?(undefined) ? default_block.call(key) : result)
66
+ post_lookup(scope, key, result.equal?(undefined) ? default_block.call(key) : result)
67
67
  end
68
68
 
69
69
  private :common
70
70
 
71
71
  def lookup(scope, key, default, override)
72
- HieraPuppet.lookup(key, default,scope, override, merge_type)
72
+ HieraPuppet.lookup(key, default, scope, override, merge_type)
73
73
  end
74
74
 
75
75
  def merge_type
76
76
  :priority
77
77
  end
78
78
 
79
- def post_lookup(key, result)
79
+ def post_lookup(scope, key, result)
80
80
  result
81
81
  end
82
82
  end
@@ -181,10 +181,20 @@ generated by running puppet agent with '--genconfig'.
181
181
  Enable full debugging.
182
182
 
183
183
  * --detailed-exitcodes:
184
- Provide transaction information via exit codes. If this is enabled, an exit
185
- code of '2' means there were changes, an exit code of '4' means there were
186
- failures during the transaction, and an exit code of '6' means there were both
187
- changes and failures.
184
+ Provide extra information about the run via exit codes; only works if
185
+ '--onetime' is also specified. If enabled, 'puppet agent' will use the
186
+ following exit codes:
187
+
188
+ 0: The run succeeded with no changes or failures; the system was already in
189
+ the desired state.
190
+
191
+ 1: The run failed.
192
+
193
+ 2: The run succeeded, and some resources were changed.
194
+
195
+ 4: The run succeeded, and some resources failed.
196
+
197
+ 6: The run succeeded, and included both changes and failures.
188
198
 
189
199
  * --digest:
190
200
  Change the certificate fingerprinting digest algorithm. The default is
@@ -83,10 +83,19 @@ configuration options can also be generated by running puppet with
83
83
  Enable full debugging.
84
84
 
85
85
  * --detailed-exitcodes:
86
- Provide transaction information via exit codes. If this is enabled, an exit
87
- code of '2' means there were changes, an exit code of '4' means there were
88
- failures during the transaction, and an exit code of '6' means there were both
89
- changes and failures.
86
+ Provide extra information about the run via exit codes. If enabled, 'puppet
87
+ apply' will use the following exit codes:
88
+
89
+ 0: The run succeeded with no changes or failures; the system was already in
90
+ the desired state.
91
+
92
+ 1: The run failed.
93
+
94
+ 2: The run succeeded, and some resources were changed.
95
+
96
+ 4: The run succeeded, and some resources failed.
97
+
98
+ 6: The run succeeded, and included both changes and failures.
90
99
 
91
100
  * --help:
92
101
  Print this help message
@@ -531,7 +531,7 @@ module Puppet
531
531
  :desc => "The module repository",
532
532
  },
533
533
  :module_working_dir => {
534
- :default => '$vardir/puppet-module',
534
+ :default => (Puppet.features.microsoft_windows? ? Dir.tmpdir() : '$vardir/puppet-module'),
535
535
  :desc => "The directory into which module tool data is stored",
536
536
  },
537
537
  :module_skeleton_dir => {
@@ -282,10 +282,29 @@ module Puppet::Environments
282
282
  @cache_expiration_service || DefaultCacheExpirationService.new
283
283
  end
284
284
 
285
+ # Returns the end of time (the next Mesoamerican Long Count cycle-end after 2012 (5125+2012) = 7137,
286
+ # of for a 32 bit machine using Ruby < 1.9.3, the year 2038.
287
+ def self.end_of_time
288
+ begin
289
+ Time.gm(7137)
290
+ rescue ArgumentError
291
+ Time.gm(2038)
292
+ end
293
+ end
294
+
295
+ END_OF_TIME = end_of_time
296
+ START_OF_TIME = Time.gm(1)
297
+
285
298
  def initialize(loader)
286
299
  @loader = loader
287
- @cache = {}
288
300
  @cache_expiration_service = Puppet::Environments::Cached.cache_expiration_service
301
+ @cache = {}
302
+
303
+ # Holds expiration times in sorted order - next to expire is first
304
+ @expirations = SortedSet.new
305
+
306
+ # Infinity since it there are no entries, this is a cache of the first to expire time
307
+ @next_expiration = END_OF_TIME
289
308
  end
290
309
 
291
310
  # @!macro loader_list
@@ -300,15 +319,34 @@ module Puppet::Environments
300
319
 
301
320
  # @!macro loader_get
302
321
  def get(name)
303
- evict_if_expired(name)
322
+ # Aggressively evict all that has expired
323
+ # This strategy favors smaller memory footprint over environment
324
+ # retrieval time.
325
+ clear_all_expired
304
326
  if result = @cache[name]
327
+ # found in cache
305
328
  return result.value
306
329
  elsif (result = @loader.get(name))
307
- @cache[name] = entry(result)
330
+ # environment loaded, cache it
331
+ cache_entry = entry(result)
332
+ @cache_expiration_service.created(result)
333
+ add_entry(name, cache_entry)
308
334
  result
309
335
  end
310
336
  end
311
337
 
338
+ # Adds a cache entry to the cache
339
+ def add_entry(name, cache_entry)
340
+ Puppet.debug {"Caching environment '#{name}' #{cache_entry.label}"}
341
+ @cache[name] = cache_entry
342
+ expires = cache_entry.expires
343
+ @expirations.add(expires)
344
+ if @next_expiration > expires
345
+ @next_expiration = expires
346
+ end
347
+ end
348
+ private :add_entry
349
+
312
350
  # Clears the cache of the environment with the given name.
313
351
  # (The intention is that this could be used from a MANUAL cache eviction command (TBD)
314
352
  def clear(name)
@@ -319,6 +357,25 @@ module Puppet::Environments
319
357
  # (The intention is that this could be used from a MANUAL cache eviction command (TBD)
320
358
  def clear_all()
321
359
  @cache = {}
360
+ @expirations.clear
361
+ @next_expiration = END_OF_TIME
362
+ end
363
+
364
+ # Clears all environments that have expired, either by exceeding their time to live, or
365
+ # through an explicit eviction determined by the cache expiration service.
366
+ #
367
+ def clear_all_expired()
368
+ t = Time.now
369
+ return if t < @next_expiration && ! @cache.any? {|name, _| @cache_expiration_service.expired?(name.to_sym) }
370
+ to_expire = @cache.select { |name, entry| entry.expires < t || @cache_expiration_service.expired?(name.to_sym) }
371
+ to_expire.each do |name, entry|
372
+ Puppet.debug {"Evicting cache entry for environment '#{name}'"}
373
+ @cache_expiration_service.evicted(name)
374
+ clear(name)
375
+ @expirations.delete(entry.expires)
376
+ Puppet.settings.clear_environment_settings(name)
377
+ end
378
+ @next_expiration = @expirations.first || END_OF_TIME
322
379
  end
323
380
 
324
381
  # This implementation evicts the cache, and always gets the current
@@ -337,9 +394,7 @@ module Puppet::Environments
337
394
  # Creates a suitable cache entry given the time to live for one environment
338
395
  #
339
396
  def entry(env)
340
- @cache_expiration_service.created(env)
341
397
  ttl = (conf = get_conf(env.name)) ? conf.environment_timeout : Puppet.settings.value(:environment_timeout)
342
- Puppet.debug {"Caching environment '#{env.name}' (cache ttl: #{ttl})"}
343
398
  case ttl
344
399
  when 0
345
400
  NotCachedEntry.new(env) # Entry that is always expired (avoids syscall to get time)
@@ -373,6 +428,14 @@ module Puppet::Environments
373
428
  def expired?
374
429
  false
375
430
  end
431
+
432
+ def label
433
+ ""
434
+ end
435
+
436
+ def expires
437
+ END_OF_TIME
438
+ end
376
439
  end
377
440
 
378
441
  # Always evicting entry
@@ -380,6 +443,14 @@ module Puppet::Environments
380
443
  def expired?
381
444
  true
382
445
  end
446
+
447
+ def label
448
+ "(ttl = 0 sec)"
449
+ end
450
+
451
+ def expires
452
+ START_OF_TIME
453
+ end
383
454
  end
384
455
 
385
456
  # Time to Live eviction policy entry
@@ -387,11 +458,20 @@ module Puppet::Environments
387
458
  def initialize(value, ttl_seconds)
388
459
  super value
389
460
  @ttl = Time.now + ttl_seconds
461
+ @ttl_seconds = ttl_seconds
390
462
  end
391
463
 
392
464
  def expired?
393
465
  Time.now > @ttl
394
466
  end
467
+
468
+ def label
469
+ "(ttl = #{@ttl_seconds} sec)"
470
+ end
471
+
472
+ def expires
473
+ @ttl
474
+ end
395
475
  end
396
476
  end
397
477
  end
@@ -1,42 +1,34 @@
1
- # Evaluates an Embedded Puppet Template (EPP) file and returns the rendered text result as a String.
1
+ # Evaluates an Embedded Puppet (EPP) template file and returns the rendered text
2
+ # result as a String.
3
+ #
4
+ # `epp('<MODULE NAME>/<TEMPLATE FILE>', <PARAMETER HASH>)`
2
5
  #
3
6
  # The first argument to this function should be a `<MODULE NAME>/<TEMPLATE FILE>`
4
- # reference, which will load `<TEMPLATE FILE>` from a module's `templates`
5
- # directory. (For example, the reference `apache/vhost.conf.epp` will load the
6
- # file `<MODULES DIRECTORY>/apache/templates/vhost.conf.epp`.)
7
- #
8
- # The second argument is optional; if present, it should be a hash containing parameters for the
9
- # template. (See below.)
10
- #
11
- # EPP supports the following tags:
12
- #
13
- # * `<%= puppet expression %>` - This tag renders the value of the expression it contains.
14
- # * `<% puppet expression(s) %>` - This tag will execute the expression(s) it contains, but renders nothing.
15
- # * `<%# comment %>` - The tag and its content renders nothing.
16
- # * `<%%` or `%%>` - Renders a literal `<%` or `%>` respectively.
17
- # * `<%-` - Same as `<%` but suppresses any leading whitespace.
18
- # * `-%>` - Same as `%>` but suppresses any trailing whitespace on the same line (including line break).
19
- # * `<%- |parameters| -%>` - When placed as the first tag declares the template's parameters.
20
- #
21
- # File based EPP supports the following visibilities of variables in scope:
22
- #
23
- # * Global scope (i.e. top + node scopes) - global scope is always visible
24
- # * Global + all given arguments - if the EPP template does not declare parameters, and arguments are given
25
- # * Global + declared parameters - if the EPP declares parameters, given argument names must match
26
- #
27
- # EPP supports parameters by placing an optional parameter list as the very first element in the EPP. As an example,
28
- # `<%- |$x, $y, $z = 'unicorn'| -%>` when placed first in the EPP text declares that the parameters `x` and `y` must be
29
- # given as template arguments when calling `inline_epp`, and that `z` if not given as a template argument
30
- # defaults to `'unicorn'`. Template parameters are available as variables, e.g.arguments `$x`, `$y` and `$z` in the example.
31
- # Note that `<%-` must be used or any leading whitespace will be interpreted as text
32
- #
33
- # Arguments are passed to the template by calling `epp` with a Hash as the last argument, where parameters
34
- # are bound to values, e.g. `epp('...', {'x'=>10, 'y'=>20})`. Excess arguments may be given
35
- # (i.e. undeclared parameters) only if the EPP templates does not declare any parameters at all.
36
- # Template parameters shadow variables in outer scopes. File based epp does never have access to variables in the
37
- # scope where the `epp` function is called from.
38
- #
39
- # @see function inline_epp for examples of EPP
7
+ # reference, which loads `<TEMPLATE FILE>` from `<MODULE NAME>`'s `templates`
8
+ # directory. In most cases, the last argument is optional; if used, it should be a
9
+ # [hash](/puppet/latest/reference/lang_data_hash.html) that contains parameters to
10
+ # pass to the template.
11
+ #
12
+ # - See the [template](/puppet/latest/reference/lang_template.html) documentation
13
+ # for general template usage information.
14
+ # - See the [EPP syntax](/puppet/latest/reference/lang_template_epp.html)
15
+ # documentation for examples of EPP.
16
+ #
17
+ # For example, to call the apache module's `templates/vhost/_docroot.epp`
18
+ # template and pass the `docroot` and `virtual_docroot` parameters, call the `epp`
19
+ # function like this:
20
+ #
21
+ # `epp('apache/templates/vhost/_docroot.epp', { 'docroot' => '/var/www/html',
22
+ # 'virtual_docroot' => '/var/www/example' })`
23
+ #
24
+ # Puppet produces a syntax error if you pass more parameters than are declared in
25
+ # the template's parameter tag. When passing parameters to a template that
26
+ # contains a parameter tag, use the same names as the tag's declared parameters.
27
+ #
28
+ # Parameters are required only if they are declared in the called template's
29
+ # parameter tag without default values. Puppet produces an error if the `epp`
30
+ # function fails to pass any required parameter.
31
+ #
40
32
  # @since 4.0.0
41
33
  #
42
34
  Puppet::Functions.create_function(:epp, Puppet::Functions::InternalFunction) do
@@ -10,8 +10,8 @@ Puppet::Functions.create_function(:hiera_include, Hiera::PuppetFunction) do
10
10
  :array
11
11
  end
12
12
 
13
- def post_lookup(key, value)
13
+ def post_lookup(scope, key, value)
14
14
  raise Puppet::ParseError, "Could not find data item #{key}" if value.nil?
15
- call_function('include', value) unless value.empty?
15
+ call_function_with_scope(scope, 'include', value) unless value.empty?
16
16
  end
17
17
  end
@@ -1,74 +1,47 @@
1
- # Evaluates an Embedded Puppet Template (EPP) string and returns the rendered text result as a String.
2
- #
3
- # EPP support the following tags:
4
- #
5
- # * `<%= puppet expression %>` - This tag renders the value of the expression it contains.
6
- # * `<% puppet expression(s) %>` - This tag will execute the expression(s) it contains, but renders nothing.
7
- # * `<%# comment %>` - The tag and its content renders nothing.
8
- # * `<%%` or `%%>` - Renders a literal `<%` or `%>` respectively.
9
- # * `<%-` - Same as `<%` but suppresses any leading whitespace.
10
- # * `-%>` - Same as `%>` but suppresses any trailing whitespace on the same line (including line break).
11
- # * `<%- |parameters| -%>` - When placed as the first tag declares the template's parameters.
12
- #
13
- # Inline EPP supports the following visibilities of variables in scope which depends on how EPP parameters
14
- # are used - see further below:
15
- #
16
- # * Global scope (i.e. top + node scopes) - global scope is always visible
17
- # * Global + Enclosing scope - if the EPP template does not declare parameters, and no arguments are given
18
- # * Global + all given arguments - if the EPP template does not declare parameters, and arguments are given
19
- # * Global + declared parameters - if the EPP declares parameters, given argument names must match
20
- #
21
- # EPP supports parameters by placing an optional parameter list as the very first element in the EPP. As an example,
22
- # `<%- |$x, $y, $z='unicorn'| -%>` when placed first in the EPP text declares that the parameters `x` and `y` must be
23
- # given as template arguments when calling `inline_epp`, and that `z` if not given as a template argument
24
- # defaults to `'unicorn'`. Template parameters are available as variables, e.g.arguments `$x`, `$y` and `$z` in the example.
25
- # Note that `<%-` must be used or any leading whitespace will be interpreted as text
26
- #
27
- # Arguments are passed to the template by calling `inline_epp` with a Hash as the last argument, where parameters
28
- # are bound to values, e.g. `inline_epp('...', {'x'=>10, 'y'=>20})`. Excess arguments may be given
29
- # (i.e. undeclared parameters) only if the EPP templates does not declare any parameters at all.
30
- # Template parameters shadow variables in outer scopes.
31
- #
32
- # Note: An inline template is best stated using a single-quoted string, or a heredoc since a double-quoted string
33
- # is subject to expression interpolation before the string is parsed as an EPP template. Here are examples
34
- # (using heredoc to define the EPP text):
35
- #
36
- # @example Various Examples using `inline_epp`
37
- #
38
- # # produces 'Hello local variable world!'
39
- # $x ='local variable'
40
- # inline_epptemplate(@(END:epp))
41
- # <%- |$x| -%>
42
- # Hello <%= $x %> world!
43
- # END
44
- #
45
- # # produces 'Hello given argument world!'
46
- # $x ='local variable world'
47
- # inline_epptemplate(@(END:epp), { x =>'given argument'})
48
- # <%- |$x| -%>
49
- # Hello <%= $x %> world!
50
- # END
51
- #
52
- # # produces 'Hello given argument world!'
53
- # $x ='local variable world'
54
- # inline_epptemplate(@(END:epp), { x =>'given argument'})
55
- # <%- |$x| -%>
56
- # Hello <%= $x %>!
57
- # END
58
- #
59
- # # results in error, missing value for y
60
- # $x ='local variable world'
61
- # inline_epptemplate(@(END:epp), { x =>'given argument'})
62
- # <%- |$x, $y| -%>
63
- # Hello <%= $x %>!
64
- # END
65
- #
66
- # # Produces 'Hello given argument planet'
67
- # $x ='local variable world'
68
- # inline_epptemplate(@(END:epp), { x =>'given argument'})
69
- # <%- |$x, $y=planet| -%>
70
- # Hello <%= $x %> <%= $y %>!
71
- # END
1
+ # Evaluates an Embedded Puppet (EPP) template string and returns the rendered
2
+ # text result as a String.
3
+ #
4
+ # `inline_epp('<EPP TEMPLATE STRING>', <PARAMETER HASH>)`
5
+ #
6
+ # The first argument to this function should be a string containing an EPP
7
+ # template. In most cases, the last argument is optional; if used, it should be a
8
+ # [hash](/puppet/latest/reference/lang_data_hash.html) that contains parameters to
9
+ # pass to the template.
10
+ #
11
+ # - See the [template](/puppet/latest/reference/lang_template.html) documentation
12
+ # for general template usage information.
13
+ # - See the [EPP syntax](/puppet/latest/reference/lang_template_epp.html)
14
+ # documentation for examples of EPP.
15
+ #
16
+ # For example, to evaluate an inline EPP template and pass it the `docroot` and
17
+ # `virtual_docroot` parameters, call the `inline_epp` function like this:
18
+ #
19
+ # `inline_epp('docroot: <%= $docroot %> Virtual docroot: <%= $virtual_docroot %>',
20
+ # { 'docroot' => '/var/www/html', 'virtual_docroot' => '/var/www/example' })`
21
+ #
22
+ # Puppet produces a syntax error if you pass more parameters than are declared in
23
+ # the template's parameter tag. When passing parameters to a template that
24
+ # contains a parameter tag, use the same names as the tag's declared parameters.
25
+ #
26
+ # Parameters are required only if they are declared in the called template's
27
+ # parameter tag without default values. Puppet produces an error if the
28
+ # `inline_epp` function fails to pass any required parameter.
29
+ #
30
+ # An inline EPP template should be written as a single-quoted string or
31
+ # [heredoc](puppet/latest/reference/lang_data_string.html#heredocs).
32
+ # A double-quoted string is subject to expression interpolation before the string
33
+ # is parsed as an EPP template.
34
+ #
35
+ # For example, to evaluate an inline EPP template using a heredoc, call the
36
+ # `inline_epp` function like this:
37
+ #
38
+ # ~~~ puppet
39
+ # # Outputs 'Hello given argument planet!'
40
+ # inline_epp(@(END), { x => 'given argument' })
41
+ # <%- | $x, $y = planet | -%>
42
+ # Hello <%= $x %> <%= $y %>!
43
+ # END
44
+ # ~~~
72
45
  #
73
46
  # @since 4.0.0
74
47
  #