Question on searching for and using data inside a structured fact

48 views
Skip to first unread message

Sean

unread,
Nov 8, 2017, 6:54:28 PM11/8/17
to Puppet Users
Hi,

I have been attempting (and failing miserably) at trying to obtain the UUID of a partition mounted in a specific directory from the partitions fact.  I'm using puppet 4.10.8.

As an example, let's say I'm looking for the UUID of /boot on my systems...

$ facter partitions
{"sda1"=>{"size"=>"1048576", "mount"=>"/boot/efi"}, "sda2"=>{"uuid"=>"14528e73-61cc-4503-b24f-47c3b6e2aee2", "size"=>"1048576", "mount"=>"/boot"}, "sda3"=>{"uuid"=>"c0f0fa3e-b389-4814-ae8b-dec3b14816fb", "size"=>"974673920"}}

I can successfully use the filter function to find the sda2 hash in puppet:

$x = $facts['partitions'].filter |$p,$d| { $d['mount' == '/boot' }
$k = keys($x)
$u = $x[k[0]]['uuid']
notify { "$u": }


This produces the desired resulting data, a string with the UUID, but it requires using puppetlabs-stdlib's keys function.  So, is there a way to accomplish this with native puppet alone?

Thanks you kindly.

R.I.Pienaar

unread,
Nov 9, 2017, 2:43:48 AM11/9/17
to puppet...@googlegroups.com
nothing wrong with keys() but...

function uuid_for_partition($needle) {
$uuid = $facts["partitions"].reduce() |$memo, $partition| {
$partition[1]["mount"] ? {
$needle => $partition[0],
default => $memo
}
}
}

notice(uuid_for_partition("/boot"))
> --
> 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...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/puppet-users/fa9679ba-72a4-4ba2-8cbf-a1695cdefa8a%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.


--
R.I.Pienaar / www.devco.net / @ripienaar
Reply all
Reply to author
Forward
0 new messages