Getting the facter value of $mount from $partitions.

160 views
Skip to first unread message

Hiu

unread,
Mar 18, 2015, 9:45:58 PM3/18/15
to puppet...@googlegroups.com
hi all,

I am wondering if I would like to retrieve the mount points values from the facter. From the facter -p, I can see that I do have the information. e.g.

partitions => {
"sda1"=>{
"mount"=>"/boot", 
"uuid"=>"4e5014d1-080a-4182-aa89-bc83159b85fb", 
"filesystem"=>"ext4", 
"size"=>"614400"}, 
"sda2"=>{
"mount"=>"/", 
"uuid"=>"edbab169-7983-4e38-9c71-24f0f88cccaa", 
"filesystem"=>"ext4", 
"size"=>"18257920"}, 
"sda3"=>{
"uuid"=>"b9674244-6686-49b0-b778-91052d78767f", 
"filesystem"=>"swap", 
"size"=>"2097152"}
}

And $mount is the one that I am looking for. Question: how can i loop through the $partitions data structure and harvest $mount and detect if there is a mount point call "/data". thanks!

jcbollinger

unread,
Mar 19, 2015, 9:52:12 AM3/19/15
to puppet...@googlegroups.com


It can be done.  Your best bet is probably a custom function or an inline template, either one of which can be used to process your data with arbitrary Ruby code.  Exactly how that would look depends a lot on what you want to do with the data, and in what form you want to receive the result.  If all you want to know is whether there is any x for which $::partitions[x]['mount'] == '/data', then it might look like this:

$has_data_partition = inline_template("<%= (! @partitions.select { | fs, opts | '/data' == opts['mount'] }.empty? ).to_s %>")
if $has_data_partition == 'true' {
 
# ...
} else {
 
# ...
}


John



Hiu

unread,
Mar 20, 2015, 1:13:22 AM3/20/15
to puppet...@googlegroups.com
hey John,

You are rock!

The codes is working as expected. Should have pick up some ruby books and start understanding it....

thanks a lot...
Reply all
Reply to author
Forward
0 new messages