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] 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();