Slackbot
11/09/2023, 8:31 AMJohan Basson
11/09/2023, 8:32 AMrun_plan('facts', 'targets' => $targets)
$debian_targets = get_targets($targets).filter |$n| { $n.facts['os']['name'] == 'Debian' }
out::message("Debian targets are: ${debian_targets}")
works simple enough and I can find hosts that has os.name set to Debian however I'm having trouble with a more complicated nested set of values.Johan Basson
11/09/2023, 8:35 AMlogical_volumes
that looks something like this:
{
"root_buster": {
"active": "active",
"attr": "-wi-ao----",
"dm_path": "/dev/mapper/vg-root_buster",
"full_name": "vg/root_buster",
"layout": "linear",
"path": "/dev/vg/root_buster",
"permissions": "writeable",
"role": "public",
"size": "8.00g",
"uuid": "POxb05-o72M-M4Th-KrUD-LnCM-Q9aQ-jYr5iM"
},
"swap": {
"active": "active",
"attr": "-wi-a-----",
"dm_path": "/dev/mapper/vg-swap",
"full_name": "vg/swap",
"layout": "linear",
"path": "/dev/vg/swap",
"permissions": "writeable",
"role": "public",
"size": "512.00m",
"uuid": "2lsnfO-KqML-dcnd-5Yfq-3Ftn-g29U-hN7nTt"
},
"usrhome": {
"active": "active",
"attr": "-wi-ao----",
"dm_path": "/dev/mapper/vg-usrhome",
"full_name": "vg/usrhome",
"layout": "linear",
"path": "/dev/vg/usrhome",
"permissions": "writeable",
"role": "public",
"size": "1.00g",
"uuid": "9TC7kR-fojW-nrdH-wwKz-oIr6-V6yV-DW92pd"
},
"usrlog": {
"active": "active",
"attr": "-wi-ao----",
"dm_path": "/dev/mapper/vg-usrlog",
"full_name": "vg/usrlog",
"layout": "linear",
"path": "/dev/vg/usrlog",
"permissions": "writeable",
"role": "public",
"size": "1.00g",
"uuid": "v5ei5f-bU2E-Q5fE-9hEC-HmpI-jeSx-4c1y1a"
},
"usrwww": {
"active": "active",
"attr": "-wi-ao----",
"dm_path": "/dev/mapper/vg-usrwww",
"full_name": "vg/usrwww",
"layout": "linear",
"path": "/dev/vg/usrwww",
"permissions": "writeable",
"role": "public",
"size": "1.00g",
"uuid": "8RWx1i-JFb0-nN0T-ogbQ-fyOm-yVXx-rSO7RE"
}
}
I'd like to filter on hosts that have the same set of keys for logical volumes.
From the comand line using facter -p and jq I would get it like this:
facter -p --json logical_volumes | jq '.logical_volumes | keys'
[
"root_buster",
"swap",
"usrhome",
"usrlog",
"usrwww"
]
I've been trying to do the same in a bolt plan using
$logical_volumes = get_targets($targets).filter |$n| { $n.facts['logical_volumes'].keys = [
'root_buster',
'swap',
'usrhome',
'usrlog',
'usrww'
]}
which doesn't work since Illegal attempt to assign to 'a Method call'. Not an assignable reference
Johan Basson
11/09/2023, 8:37 AMfacts
moduleYury Bushmelev
11/09/2023, 8:41 AM=
is assignment, you need ==
I guessYury Bushmelev
11/09/2023, 8:41 AMJohan Basson
11/09/2023, 9:04 AM==
if that's my only problem I'll be so embarrassedJohan Basson
11/09/2023, 9:25 AMget_targets($targets).filter |$n| { $n.facts['logical_volumes'].keys == ['root_buster','swap','usrhome','usrlog','usrwww'] }
Yury Bushmelev
11/09/2023, 12:05 PM