Ask Your Question

Custom fact - get disk size?

asked 2015-06-09 05:41:12 -0500

qwerty_face gravatar image

I have a custom fact that is using the following to obtain the root volume disk size:

s = Facter::Core::Execution.exec('df -k | head -n 2 | tail -n 1 | awk \'{print $2}\'').chomp


s = Facter::Core::Execution.exec('df -hk /myfolder | tail -n 1 | awk \'{print $1}\'').chomp

I then do some arithmetic on sand compute a value in Gb. It is not an ideal solution and will cause problems later on. Ideally I'd have a way to interrogate volumes/disks and get the associated attributes rather than executing this shell command. As is explained in the accepted answer here:

On that note is it possible to use statements such as:

require 'sys/filesystem'

From within custom facts? If so, how would one go about installing the 'sys/filesystem' library as suggested in that SO thread?

All input appreciated.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2015-06-09 06:17:30 -0500

you've probably seen it already but there is a blockdevice fact - if you have a standard build and know root is always on sda say you can do a facter blockdevice_sda which will give the size... there is also a partitions fact that gives details if its just the slice you're after rather than the underlying physical disk.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools



Asked: 2015-06-09 05:41:12 -0500

Seen: 1,940 times

Last updated: Jun 09 '15