Skip to content

Commit b565f7f

Browse files
committed
Make ensure_packages an InternalFunction
To preserve original behaviour of the created package(s) being contained within the class that called `ensure_packages`, the function needs to be an `InternalFunction` and call `ensure_resource(s)` with the correct scope.
1 parent 82b74e2 commit b565f7f

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

lib/puppet/functions/ensure_packages.rb

+5-4
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,20 @@
44
#
55
# It optionally takes a hash as a second parameter that will be passed as the
66
# third argument to the ensure_resource() function.
7-
Puppet::Functions.create_function(:ensure_packages) do
7+
Puppet::Functions.create_function(:ensure_packages, Puppet::Functions::InternalFunction) do
88
# @param packages
99
# The packages to ensure are installed. If it's a Hash it will be passed to `ensure_resource`
1010
# @param default_attributes
1111
# Default attributes to be passed to the `ensure_resource()` function
1212
# @return [Undef] Returns nothing.
1313
dispatch :ensure_packages do
14+
scope_param
1415
param 'Variant[String[1], Array[String[1]], Hash[String[1], Any]]', :packages
1516
optional_param 'Hash', :default_attributes
1617
return_type 'Undef'
1718
end
1819

19-
def ensure_packages(packages, default_attributes = nil)
20+
def ensure_packages(scope, packages, default_attributes = nil)
2021
if default_attributes
2122
defaults = { 'ensure' => 'installed' }.merge(default_attributes)
2223
if defaults['ensure'] == 'present'
@@ -27,10 +28,10 @@ def ensure_packages(packages, default_attributes = nil)
2728
end
2829

2930
if packages.is_a?(Hash)
30-
call_function('ensure_resources', 'package', packages.dup, defaults)
31+
scope.call_function('ensure_resources', ['package', packages.dup, defaults])
3132
else
3233
Array(packages).each do |package_name|
33-
call_function('ensure_resource', 'package', package_name, defaults)
34+
scope.call_function('ensure_resource', ['package', package_name, defaults])
3435
end
3536
end
3637
nil

0 commit comments

Comments
 (0)