From f0d4066321533e6136956671b7073c115c64bf2d Mon Sep 17 00:00:00 2001 From: Michael Hashizume Date: Wed, 28 Aug 2024 14:52:11 -0700 Subject: [PATCH] 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. --- lib/facter/resolvers/partitions.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/facter/resolvers/partitions.rb b/lib/facter/resolvers/partitions.rb index cca2ca365b..8832515503 100644 --- a/lib/facter/resolvers/partitions.rb +++ b/lib/facter/resolvers/partitions.rb @@ -123,7 +123,8 @@ 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 + # Return if the version of lsblk is too old (< 2.22) to support the --version flag + 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