This message was deleted.
# bolt
s
This message was deleted.
j
Copy code
run_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.
Here's what I mean. We have a fact called
logical_volumes
that looks something like this:
Copy code
{
  "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'
Copy code
[
  "root_buster",
  "swap",
  "usrhome",
  "usrlog",
  "usrwww"
]
I've been trying to do the same in a bolt plan using
Copy code
$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
Any suggestions on how I can achieve this natively in bolt, as I would hate to have to do something like a run_command or write a task that pulls facts since that would essentially be re-inventing the
facts
module
y
=
is assignment, you need
==
I guess
though, I’m not sure it’ll work as expected.. I’ll re-read it later and maybe will suggest something
j
🤦 missed the
==
if that's my only problem I'll be so embarrassed
Ok looks like what I needed was
get_targets($targets).filter |$n| { $n.facts['logical_volumes'].keys == ['root_buster','swap','usrhome','usrlog','usrwww'] }
y
maybe you need to sort both sides but otherwise it looks ok