Given a data structure like
$local_users => {
"user" => {
"ssh" => {
"config_entries" => [
{ "host" => "dummyhost",
"lines" => [
"ProxyCommand /usr/bin/corkscrew proxy.example.net 8080 %h %p"
]
}
]
}
}
}
I've put together a couple of reduce calls, but not really sure if there is a more effective way to determine if there is an element matching some condition. I think this will at least this will start skipping subsequent items if a match is found, but seems a little clunky doing 3 reduce calls to extract something nested this deeply and wondering if there are any better patterns in puppet for extracting data to determine if something is required or not.
$require_corkscrew = $local_users.reduce(false) |$memo, $user| {
$memo or dig44($user[1], ['ssh', 'config_entries'], []).reduce |$memo, $entry| {
$memo or $entry['lines'].reduce |$memo, $line| {
$memo or $line.match(/ProxyCommand.*corkscrew/)
}
}
}
if $require_corkscrew {
$corkscrew_ensure = 'present'
} else {
$corkscrew_ensure = 'absent'
}
package {'corkscrew':
ensure => $corkscrew_ensure,
}