21
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
|
# File 'puppet/modules/wmflib/lib/puppet/parser/functions/require_package.rb', line 21
newfunction(:require_package, :arity => -2) do |args|
Puppet::Parser::Functions.function :create_resources
args.flatten.each do |package_name|
class_name = 'packages::' + package_name.tr('-+', '_')
host = compiler.topscope.find_hostclass(class_name)
unless host
host = Puppet::Resource::Type.new(:hostclass, class_name)
compiler.environment.known_resource_types.add_hostclass(host)
end
cls = Puppet::Parser::Resource.new(
'class', class_name, :scope => compiler.topscope)
catalog.add_resource(cls) rescue nil
host.evaluate_code(cls) rescue nil
begin
host_scope = compiler.topscope.class_scope(host)
host_scope.call_function(:create_resources,
['package', { package_name => { :ensure => :present } }])
rescue Puppet::Resource::Catalog::DuplicateResourceError
end
call_function :require, [class_name]
end
end
|