From 4d19c937eab00000c7e4002cf52785f4b031a1cc Mon Sep 17 00:00:00 2001 From: stantheman0128 Date: Thu, 1 Oct 2026 19:53:43 +0800 Subject: [PATCH 1/2] Fix is_redhat IDs for RHEL rebuilds lsb_release -s -i on current RHEL rebuilds reports IDs missing from @redhat_clones, so pkg lookups died once redhat-lsb-core was installed. Match the OS name exactly so substrings like Red no longer false-match. Fixes #1661 --- lib/Rex/Commands/Gather.pm | 23 ++++++++++++++--------- t/is_redhat.t | 28 ++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 9 deletions(-) create mode 100644 t/is_redhat.t diff --git a/lib/Rex/Commands/Gather.pm b/lib/Rex/Commands/Gather.pm index cdff9bc1f..42308f443 100644 --- a/lib/Rex/Commands/Gather.pm +++ b/lib/Rex/Commands/Gather.pm @@ -258,17 +258,22 @@ sub is_freebsd { sub is_redhat { my $os = @_ ? shift : get_operating_system(); - my @redhat_clones = ( - "Fedora", "Redhat", - "CentOS", "Scientific", - "RedHatEnterpriseServer", "RedHatEnterpriseES", - "RedHatEnterpriseWorkstation", "RedHatEnterpriseWS", - "Amazon", "ROSAEnterpriseServer", - "CloudLinuxServer", "XenServer", - "OracleServer", "Virtuozzo", + # lsb_release IDs for current RHEL rebuilds (#1661). + # Match exactly so a substring like Red does not hit Redhat. + my @redhat_clones = qw( + Fedora Redhat + CentOS Scientific + RedHatEnterpriseServer RedHatEnterpriseES + RedHatEnterpriseWorkstation RedHatEnterpriseWS + RedHatEnterprise Amazon + ROSAEnterpriseServer CloudLinuxServer + XenServer OracleServer + OracleLinux Virtuozzo + Rocky RockyLinux + AlmaLinux CentOSStream ); - if ( grep { /$os/i } @redhat_clones ) { + if ( grep { lc eq lc $os } @redhat_clones ) { return 1; } } diff --git a/t/is_redhat.t b/t/is_redhat.t new file mode 100644 index 000000000..68b4bfe07 --- /dev/null +++ b/t/is_redhat.t @@ -0,0 +1,28 @@ +#!/usr/bin/env perl + +use v5.14.4; +use warnings; + +our $VERSION = '9999.99.99_99'; # VERSION + +use Test::More; +use lib 'lib'; + +local $INC{'Net/OpenSSH/ShellQuoter.pm'} = 1; +require Rex::Commands::Gather; + +my @should = qw( + Fedora Redhat CentOS Rocky rocky RockyLinux AlmaLinux CentOSStream + OracleLinux RedHatEnterprise RedHatEnterpriseServer +); +for my $os (@should) { + ok( Rex::Commands::Gather::is_redhat($os), "is_redhat($os)" ); +} + +ok( + !Rex::Commands::Gather::is_redhat('Red'), + 'is_redhat(Red) must not match via substring' +); +ok( !Rex::Commands::Gather::is_redhat('Debian'), 'is_redhat(Debian) is false' ); + +done_testing(); From 4ea4621c9a6e200c59787ffd9bf4e5c67b43551d Mon Sep 17 00:00:00 2001 From: stantheman0128 Date: Thu, 1 Oct 2026 19:53:43 +0800 Subject: [PATCH 2/2] Note is_redhat ID fixes in ChangeLog --- ChangeLog | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ChangeLog b/ChangeLog index 15e67613d..cea9926ff 100644 --- a/ChangeLog +++ b/ChangeLog @@ -4,6 +4,8 @@ Revision history for Rex [API CHANGES] [BUG FIXES] + - Recognize Rocky, AlmaLinux, CentOS Stream, and Oracle Linux lsb_release IDs in is_redhat (#1661) + - Compare is_redhat OS names exactly instead of as an unanchored regex (#1661) [DOCUMENTATION]