On 2020-03-19 22:11, Helmut Schneider wrote:
Hi,
class abc {
keys($netconfig['interfaces']).each |String $interface| {
if $netconfig['interfaces'][$interface]['ip6'] {
$myvariable = 'yes'
break()
}
}
if $myvariable == 'yes' {
do something
}
}
How can I access $myvariable?
You cannot access local variables from outside a lambda using the each
function - its contract is to return the input to allow chaining. What
you are actually doing is reducing a collection of interfaces to a
single value - which you can do with the reduce() function. In this
particular case it seems much simpler as you are really asking if
there is any interface that has something that is true for 'ip6' - you
can therefore use the `any()` function.
Perhaps something like this:
if $netconfig['interfaces'].any() |$k, $v| { $v['ip6'] =~ NotUndef } {
# do something
}
No need for a variable or anything - if you do need one do this:
$myvariable = $netconfig['interfaces'].any() |$k, $v| {
$v['ip6'] =~ NotUndef
}
if $myvariable {
# do something
}
- henrik
--
Visit my Blog "Puppet on the Edge"
http://puppet-on-the-edge.blogspot.se/
--
You received this message because you are subscribed to the Google Groups "Puppet
Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to puppet-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/puppet-users/r50png%241iav%241%40ciao.gmane.io.