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
|
# File 'puppet/modules/wmflib/lib/puppet/parser/functions/role.rb', line 38
newfunction(:role, :arity => -1) do |args|
if !is_nodescope?
raise Puppet::ParseError,
"role can only be used in node scope, while you are in scope #{self}"
end
container = '_roles'
rolevar = compiler.topscope.lookupvar(container)
if rolevar
raise Puppet::ParseError,
"Using 'role' multiple times might yield unexpected results, use 'role role1, role2' instead"
else
compiler.topscope.setvar(container, {})
rolevar = compiler.topscope.lookupvar(container)
end
args = args.map do |x|
if x.start_with? '::'
x.gsub(/^::/, '')
else
x
end
end
args.each do |arg|
rolevar[arg] = true
end
args.each do |arg|
rolename = 'role::' + arg
role_class = compiler.topscope.find_hostclass(rolename)
if role_class
send Puppet::Parser::Functions.function(:include), [rolename]
else
raise Puppet::ParseError, "Role class #{rolename} not found"
end
end
end
|