Skip to content

Commit

Permalink
Add error handling for older lsblk
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mhashizume committed Aug 29, 2024
1 parent b6cf607 commit 0893a21
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion lib/facter/resolvers/partitions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def populate_from_lsblk(partition_name, blkid_and_lsblk)
return {} unless available?('lsblk', blkid_and_lsblk)

lsblk_version_raw = Facter::Core::Execution.execute('lsblk --version 2>&1', logger: log)
lsblk_version = lsblk_version_raw.match(/ \d\.\d+/)[0].to_f
lsblk_version_raw.match?(/\d\.\d+/) ? lsblk_version = lsblk_version_raw.match(/\d\.\d+/)[0].to_f : (return {})

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

0 comments on commit 0893a21

Please sign in to comment.