Skip to content

Commit f0d4066

Browse files
committed
Add error handling for older lsblk
The partitions resolver uses `lsblk --version` to determine the version of lsblk and what features it has available to it. The --version flag was not added until lsblk 2.22 in 2012, so versions prior to that will respond with `lsblk: unrecognized option '--version'`. Puppet still supports older operating systems like SUSE Enterprise Linux 11 that may ship versions of lsblk that do not support --version. This commit updates the partitions resolver to handle errors when determining the version of lsblk and to fall back to blkid when lsblk is too old to support --version.
1 parent b6cf607 commit f0d4066

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

lib/facter/resolvers/partitions.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,8 @@ def populate_from_lsblk(partition_name, blkid_and_lsblk)
123123
return {} unless available?('lsblk', blkid_and_lsblk)
124124

125125
lsblk_version_raw = Facter::Core::Execution.execute('lsblk --version 2>&1', logger: log)
126-
lsblk_version = lsblk_version_raw.match(/ \d\.\d+/)[0].to_f
126+
# Return if the version of lsblk is too old (< 2.22) to support the --version flag
127+
lsblk_version_raw.match?(/ \d\.\d+/) ? lsblk_version = lsblk_version_raw.match(/ \d\.\d+/)[0].to_f : (return {})
127128

128129
# The -p/--paths option was added in lsblk 2.23, return early and fall back to blkid with earlier versions
129130
return {} if lsblk_version < 2.23

0 commit comments

Comments
 (0)