Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down
23 changes: 14 additions & 9 deletions lib/Rex/Commands/Gather.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
28 changes: 28 additions & 0 deletions t/is_redhat.t
Original file line number Diff line number Diff line change
@@ -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();
Loading