Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 22 additions & 8 deletions lib/facter/resolvers/partitions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,13 @@ def execute_and_extract_blkid_info
def populate_from_lsblk(partition_name, blkid_and_lsblk)
return {} unless available?('lsblk', blkid_and_lsblk)

blkid_and_lsblk[:lsblk] ||= Facter::Core::Execution.execute('lsblk -fp', logger: log)
lsblk_version_raw = Facter::Core::Execution.execute('lsblk --version 2>&1', logger: log)
lsblk_version = lsblk_version_raw.match(/ \d\.\d+/)[0].to_f
blkid_and_lsblk[:lsblk] ||= if lsblk_version >= 2.25
Facter::Core::Execution.execute('lsblk -p -P -o NAME,FSTYPE,LABEL,UUID,PARTTYPE', logger: log)
else
Facter::Core::Execution.execute('lsblk -p -P -o NAME,FSTYPE,LABEL,UUID', logger: log)
end

part_info = blkid_and_lsblk[:lsblk].match(/#{partition_name}.*/).to_s.split(' ')
return {} if part_info.empty?
Expand All @@ -130,13 +136,21 @@ def populate_from_lsblk(partition_name, blkid_and_lsblk)
end

def parse_part_info(part_info)
result = { filesystem: part_info[1] }

if part_info.count.eql?(5)
result[:label] = part_info[2]
result[:uuid] = part_info[3]
else
result[:uuid] = part_info[2]
result = {}

part_info.each do |setting|
simple_string = setting.delete('"')
key, value = simple_string.split('=')
case key
when 'FSTYPE'
result['filesystem'] = value
when 'LABEL'
result['label'] = value
when 'UUID'
result['uuid'] = value
when 'PARTTYPE'
result['type_uuid'] = value
end
end

result
Expand Down