|
1 | 1 | # frozen_string_literal: true |
2 | 2 |
|
3 | | -# @summary Takes a list of packages and only installs them if they don't already exist. |
4 | | -# |
5 | | -# It optionally takes a hash as a second parameter that will be passed as the |
6 | | -# third argument to the ensure_resource() function. |
7 | | -Puppet::Functions.create_function(:ensure_packages, Puppet::Functions::InternalFunction) do |
8 | | - # @param packages |
9 | | - # The packages to ensure are installed. |
10 | | - # @param default_attributes |
11 | | - # Default attributes to be passed to the `ensure_resource()` function |
12 | | - # @return [Undef] Returns nothing. |
13 | | - dispatch :ensure_packages do |
14 | | - scope_param |
15 | | - param 'Variant[String[1], Array[String[1]]]', :packages |
16 | | - optional_param 'Hash', :default_attributes |
17 | | - return_type 'Undef' |
18 | | - end |
19 | | - |
20 | | - # @param packages |
21 | | - # The packages to ensure are installed. The keys are packages and values are the attributes specific to that package. |
22 | | - # @param default_attributes |
23 | | - # Default attributes. Package specific attributes from the `packages` parameter will take precedence. |
24 | | - # @return [Undef] Returns nothing. |
25 | | - dispatch :ensure_packages_hash do |
26 | | - scope_param |
27 | | - param 'Hash[String[1], Any]', :packages |
28 | | - optional_param 'Hash', :default_attributes |
29 | | - return_type 'Undef' |
30 | | - end |
31 | | - |
32 | | - def ensure_packages(scope, packages, default_attributes = {}) |
33 | | - Array(packages).each do |package_name| |
34 | | - defaults = { 'ensure' => 'installed' }.merge(default_attributes) |
35 | | - |
36 | | - # `present` and `installed` are aliases for the `ensure` attribute. If `ensure` is set to either of these values replace |
37 | | - # with `installed` by default but `present` if this package is already in the catalog with `ensure => present` |
38 | | - defaults['ensure'] = default_ensure(package_name) if ['present', 'installed'].include?(defaults['ensure']) |
| 3 | +# THIS FILE WAS GENERATED BY `rake regenerate_unamespaced_shims` |
39 | 4 |
|
40 | | - scope.call_function('ensure_resource', ['package', package_name, defaults]) |
41 | | - end |
42 | | - nil |
| 5 | +# @summary DEPRECATED. Use the namespaced function [`stdlib::ensure_packages`](#stdlibensure_packages) instead. |
| 6 | +Puppet::Functions.create_function(:ensure_packages) do |
| 7 | + dispatch :deprecation_gen do |
| 8 | + repeated_param 'Any', :args |
43 | 9 | end |
44 | | - |
45 | | - def ensure_packages_hash(scope, packages, default_attributes = {}) |
46 | | - packages.each do |package, attributes| |
47 | | - ensure_packages(scope, package, default_attributes.merge(attributes)) |
48 | | - end |
49 | | - nil |
50 | | - end |
51 | | - |
52 | | - private |
53 | | - |
54 | | - def default_ensure(package_name) |
55 | | - if call_function('defined_with_params', "Package[#{package_name}]", { 'ensure' => 'present' }) |
56 | | - 'present' |
57 | | - else |
58 | | - 'installed' |
59 | | - end |
| 10 | + def deprecation_gen(*args) |
| 11 | + call_function('deprecation', 'ensure_packages', 'This function is deprecated, please use stdlib::ensure_packages instead.') |
| 12 | + call_function('stdlib::ensure_packages', *args) |
60 | 13 | end |
61 | 14 | end |
0 commit comments