Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'facter'
- # We only want this to run for Linux boxes with a 2.6+ kernel version
- if Facter.value(:kernel) == 'Linux'
- sysfs_block_directory = '/sys/block/'
- blockdevices = []
- # This should prevent Linux boxes with < 2.6 kernels from running
- if File.exists?(sysfs_block_directory)
- # Iterate over each file in the /sys/block directory and skip ones that do not have a device subdirectory
- Dir.entries(sysfs_block_directory).each do |device|
- sysfs_device_directory = sysfs_block_directory + device + "/device"
- next unless File.exist?(sysfs_device_directory)
- # Add the device to the blockdevices list, which is returned as it's own fact later on
- blockdevices << device
- sizefile = sysfs_block_directory + device + "/size"
- if File.exist?(sizefile)
- Facter.add("#{device}_gb".to_sym) do
- confine :osfamily => 'RedHat'
- setcode { IO.read(sizefile).strip.to_i * 512 / 1073741824 }
- end
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment