-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy patharray_splat.pp
60 lines (43 loc) · 1.63 KB
/
array_splat.pp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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
56
57
58
59
60
# What does array splatting actually do, outside a function call?
$myary = ['thing', 1, 5, 'other']
notify {'first':
message => "${spew($myary)}",
}
notify {'second':
message => "${spew(*$myary)}",
}
notify {'third':
message => *$myary,
}
notify {'fourth':
message => $myary,
}
# So if you just interpolate the array and the splatted array, they're indistinguishable; in a function call, it does what it says on the tin. Also, the spec says you can do that in case and selector options, as well.
$nodelist = ['wren.local', 'rook.local', 'magpie.lan', 'other.lan']
$non_matching = ['crow.local', 'albatross.local']
# This won't work:
# node $nodelist {
# this won't work either:
# node *$nodelist {
# notify {"this node actually matched!":}
# }
# So, you can't splat into node definitions. But you can apparently splat into cases and selectors:
case $trusted['certname'] {
default: { notify {"Matched the default for some reason??":} }
*$non_matching: { notify {"Matched the non-matching list for some reason??":} }
*$nodelist: { notify {"matched as expected":} }
}
# How about splatting a scalar?
notify {'something weird':
# message => spew(*5),
message => "${*undef}",
# message => "${*5}",
# message => spew(*undef),
}
# Just results in the original value if it's in a comma-able context. If not in a comma-able context, it wraps the value in an array first. So, apparently it arrayifies it and THEN splats it.
# How about splatting a hash?
$myhsh = {'a' => 5, 'b' => 7}
notify {'something even weirder':
message => "${*$myhsh}",
}
#... defined 'message' as '[[a, 5], [b, 7]]' ... I don't know what to make of that.