From 5b2a524546825c057f984ae1c5002760b87732be Mon Sep 17 00:00:00 2001 From: Ewoud Kohl van Wijngaarden Date: Tue, 22 Dec 2020 19:03:40 +0100 Subject: [PATCH] Use operatingsystemmajrelease fact This fact was introduced in Facter 1.7 which by now can be assumed. By now it's already deprecated in favor of $facts['os']['release']['major'] but the rest of the module isn't converted so this keeps it consistent. CentOS 8 stream doesn't have a minor version and the previous comparison code failed. There are a lot more odd cases with facts, but I don't want to touch too much code. --- manifests/default_mods.pp | 2 +- manifests/init.pp | 2 +- manifests/mod/fastcgi.pp | 2 +- manifests/mod/proxy_html.pp | 4 ++-- manifests/params.pp | 28 ++++++++++++++-------------- manifests/version.pp | 15 ++++----------- spec/spec_helper_local.rb | 7 ++++++- 7 files changed, 29 insertions(+), 31 deletions(-) diff --git a/manifests/default_mods.pp b/manifests/default_mods.pp index 8e7b5d0283..255c9239f3 100644 --- a/manifests/default_mods.pp +++ b/manifests/default_mods.pp @@ -17,7 +17,7 @@ if versioncmp($apache_version, '2.4') >= 0 { # Lets fork it # Do not try to load mod_systemd on RHEL/CentOS 6 SCL. - if ( !($::osfamily == 'redhat' and versioncmp($::operatingsystemrelease, '7.0') == -1) and !($::operatingsystem == 'Amazon') ) { + if ( !($::osfamily == 'redhat' and versioncmp($::operatingsystemmajrelease, '7') == -1) and !($::operatingsystem == 'Amazon') ) { if ($use_systemd) { ::apache::mod { 'systemd': } } diff --git a/manifests/init.pp b/manifests/init.pp index cae2ba92a5..f01d101bcc 100755 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -551,7 +551,7 @@ default => '(event|itk|prefork|worker)' } - if $::osfamily == 'RedHat' and $apache::version::distrelease == '7' { + if $::osfamily == 'RedHat' and $facts['operatingsystemmajrelease'] == '7' { # On redhat 7 the ssl.conf lives in /etc/httpd/conf.d (the confd_dir) # when all other module configs live in /etc/httpd/conf.modules.d (the # mod_dir). On all other platforms and versions, ssl.conf lives in the diff --git a/manifests/mod/fastcgi.pp b/manifests/mod/fastcgi.pp index d24dcbf0da..a3445c9179 100644 --- a/manifests/mod/fastcgi.pp +++ b/manifests/mod/fastcgi.pp @@ -5,7 +5,7 @@ # class apache::mod::fastcgi { include apache - if ($::osfamily == 'Redhat' and versioncmp($::operatingsystemrelease, '7.0') >= 0) { + if ($::osfamily == 'Redhat' and versioncmp($::operatingsystemmajrelease, '7') >= 0) { fail('mod_fastcgi is no longer supported on el7 and above.') } if ($facts['os']['name'] == 'Ubuntu' and versioncmp($facts['os']['release']['major'], '18.04') >= 0) { diff --git a/manifests/mod/proxy_html.pp b/manifests/mod/proxy_html.pp index 22a576641e..0205af848c 100644 --- a/manifests/mod/proxy_html.pp +++ b/manifests/mod/proxy_html.pp @@ -21,13 +21,13 @@ } case $::operatingsystem { 'Ubuntu': { - $loadfiles = $apache::params::distrelease ? { + $loadfiles = $facts['operatingsystemmajrelease'] ? { '10' => ['/usr/lib/libxml2.so.2'], default => ["/usr/lib/${gnu_path}-linux-gnu/libxml2.so.2"], } } 'Debian': { - $loadfiles = $apache::params::distrelease ? { + $loadfiles = $facts['operatingsystemmajrelease'] ? { '6' => ['/usr/lib/libxml2.so.2'], default => ["/usr/lib/${gnu_path}-linux-gnu/libxml2.so.2"], } diff --git a/manifests/params.pp b/manifests/params.pp index bad6f3e5f7..d26227cf14 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -61,7 +61,7 @@ $server_root = "${httpd_root}/etc/httpd" $conf_dir = "${httpd_dir}/conf" $confd_dir = "${httpd_dir}/conf.d" - $mod_dir = $apache::version::distrelease ? { + $mod_dir = $facts['operatingsystemmajrelease'] ? { '7' => "${httpd_dir}/conf.modules.d", default => "${httpd_dir}/conf.d", } @@ -107,11 +107,11 @@ $mime_support_package = 'mailcap' $mime_types_config = '/etc/mime.types' $docroot = "${httpd_root}/var/www/html" - $alias_icons_path = $apache::version::distrelease ? { + $alias_icons_path = $facts['operatingsystemmajrelease'] ? { '7' => "${httpd_root}/usr/share/httpd/icons", default => '/var/www/icons', } - $error_documents_path = $apache::version::distrelease ? { + $error_documents_path = $facts['operatingsystemmajrelease'] ? { '7' => "${httpd_root}/usr/share/httpd/error", default => '/var/www/error' } @@ -172,7 +172,7 @@ # Amazon Linux 2 uses the /conf.modules.d/ dir $mod_dir = "${httpd_dir}/conf.modules.d" } else { - $mod_dir = $apache::version::distrelease ? { + $mod_dir = $facts['operatingsystemmajrelease'] ? { '7' => "${httpd_dir}/conf.modules.d", '8' => "${httpd_dir}/conf.modules.d", default => "${httpd_dir}/conf.d", @@ -200,7 +200,7 @@ $suphp_addhandler = 'php5-script' $suphp_engine = 'off' $suphp_configpath = undef - $php_version = $apache::version::distrelease ? { + $php_version = $facts['operatingsystemmajrelease'] ? { '8' => '7', # RedHat8 default => '5', # RedHat5, RedHat6, RedHat7 } @@ -211,13 +211,13 @@ 'auth_gssapi' => 'mod_auth_gssapi', 'auth_mellon' => 'mod_auth_mellon', 'auth_openidc' => 'mod_auth_openidc', - 'authnz_ldap' => $apache::version::distrelease ? { + 'authnz_ldap' => $facts['operatingsystemmajrelease'] ? { '7' => 'mod_ldap', '8' => 'mod_ldap', default => 'mod_authz_ldap', }, 'authnz_pam' => 'mod_authnz_pam', - 'fastcgi' => $apache::version::distrelease ? { + 'fastcgi' => $facts['operatingsystemmajrelease'] ? { '5' => 'mod_fastcgi', '6' => 'mod_fastcgi', default => undef, @@ -225,7 +225,7 @@ 'fcgid' => 'mod_fcgid', 'geoip' => 'mod_geoip', 'intercept_form_submit' => 'mod_intercept_form_submit', - 'ldap' => $apache::version::distrelease ? { + 'ldap' => $facts['operatingsystemmajrelease'] ? { '5' => undef, '6' => undef, default => 'mod_ldap', @@ -239,7 +239,7 @@ # https://www.phusionpassenger.com/library/install/apache/install/oss/el7/ 'passenger' => 'mod_passenger', 'perl' => 'mod_perl', - 'php5' => $apache::version::distrelease ? { + 'php5' => $facts['operatingsystemmajrelease'] ? { '5' => 'php53', default => 'php', }, @@ -252,7 +252,7 @@ # See http://wiki.aaf.edu.au/tech-info/sp-install-guide 'shibboleth' => 'shibboleth', 'ssl' => 'mod_ssl', - 'wsgi' => $apache::version::distrelease ? { + 'wsgi' => $facts['operatingsystemmajrelease'] ? { '8' => 'python3-mod_wsgi', # RedHat8 default => 'mod_wsgi', # RedHat5, RedHat6, RedHat7 }, @@ -264,7 +264,7 @@ } $mod_libs = { 'nss' => 'libmodnss.so', - 'wsgi' => $apache::version::distrelease ? { + 'wsgi' => $facts['operatingsystemmajrelease'] ? { '8' => 'mod_wsgi_python3.so', default => 'mod_wsgi.so', }, @@ -278,12 +278,12 @@ $mime_support_package = 'mailcap' $mime_types_config = '/etc/mime.types' $docroot = '/var/www/html' - $alias_icons_path = $apache::version::distrelease ? { + $alias_icons_path = $facts['operatingsystemmajrelease'] ? { '7' => '/usr/share/httpd/icons', '8' => '/usr/share/httpd/icons', default => '/var/www/icons', } - $error_documents_path = $apache::version::distrelease ? { + $error_documents_path = $facts['operatingsystemmajrelease'] ? { '7' => '/usr/share/httpd/error', '8' => '/usr/share/httpd/error', default => '/var/www/error' @@ -790,7 +790,7 @@ $verify_command = '/usr/sbin/apachectl -t' } - if $::osfamily == 'RedHat' and versioncmp($::operatingsystemrelease, '8.0') >= 0 { + if $::osfamily == 'RedHat' and versioncmp($facts['operatingsystemmajrelease'], '8') >= 0 { $ssl_protocol = ['all'] # Implementations of the SSLv2 and SSLv3 protocol versions have been removed from OpenSSL (and hence mod_ssl) because these are no longer considered secure. For additional documentation https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/8/html/deploying_different_types_of_servers/setting-apache-web-server_deploying-different-types-of-servers } else { $ssl_protocol = ['all', '-SSLv2', '-SSLv3'] diff --git a/manifests/version.pp b/manifests/version.pp index 36e2a04043..7ebd591c59 100644 --- a/manifests/version.pp +++ b/manifests/version.pp @@ -6,13 +6,6 @@ Optional[String] $scl_httpd_version = undef, Optional[String] $scl_php_version = undef, ) { - # This will be 5 or 6 on RedHat, 6 or wheezy on Debian, 12 or quantal on Ubuntu, etc. - $osr_array = split($::operatingsystemrelease,'[\/\.]') - $distrelease = $osr_array[0] - if ! $distrelease { - fail("Class['apache::version']: Unparsable \$::operatingsystemrelease: ${::operatingsystemrelease}") - } - case $::osfamily { 'RedHat': { if $scl_httpd_version { @@ -20,16 +13,16 @@ } elsif ($::operatingsystem == 'Amazon') { $default = '2.2' - } elsif ($::operatingsystem == 'Fedora' and versioncmp($distrelease, '18') >= 0) or ($::operatingsystem != 'Fedora' and versioncmp($distrelease, '7') >= 0) { + } elsif ($::operatingsystem == 'Fedora' and versioncmp($facts['operatingsystemmajrelease'], '18') >= 0) or ($::operatingsystem != 'Fedora' and versioncmp($facts['operatingsystemmajrelease'], '7') >= 0) { $default = '2.4' } else { $default = '2.2' } } 'Debian': { - if $::operatingsystem == 'Ubuntu' and versioncmp($::operatingsystemrelease, '13.10') >= 0 { + if $::operatingsystem == 'Ubuntu' and versioncmp($facts['operatingsystemmajrelease'], '13.10') >= 0 { $default = '2.4' - } elsif $::operatingsystem == 'Debian' and versioncmp($distrelease, '8') >= 0 { + } elsif $::operatingsystem == 'Debian' and versioncmp($facts['operatingsystemmajrelease'], '8') >= 0 { $default = '2.4' } else { $default = '2.2' @@ -42,7 +35,7 @@ $default = '2.4' } 'Suse': { - if ($::operatingsystem == 'SLES' and versioncmp($::operatingsystemrelease, '12') >= 0) or ($::operatingsystem == 'OpenSuSE' and versioncmp($::operatingsystemrelease, '42') >= 0) { + if ($::operatingsystem == 'SLES' and versioncmp($facts['operatingsystemmajrelease'], '12') >= 0) or ($::operatingsystem == 'OpenSuSE' and versioncmp($facts['operatingsystemmajrelease'], '42') >= 0) { $default = '2.4' } else { $default = '2.2' diff --git a/spec/spec_helper_local.rb b/spec/spec_helper_local.rb index b380956a21..b5031e3e0f 100644 --- a/spec/spec_helper_local.rb +++ b/spec/spec_helper_local.rb @@ -65,6 +65,7 @@ osfamily: 'RedHat', operatingsystem: 'Fedora', operatingsystemrelease: '17', + operatingsystemmajrelease: '17', path: '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', } end @@ -78,6 +79,7 @@ osfamily: 'RedHat', operatingsystem: 'Fedora', operatingsystemrelease: '21', + operatingsystemmajrelease: '21', path: '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', } end @@ -91,6 +93,7 @@ osfamily: 'RedHat', operatingsystem: 'Fedora', operatingsystemrelease: '28', + operatingsystemmajrelease: '28', path: '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', } end @@ -104,6 +107,7 @@ osfamily: 'RedHat', operatingsystem: 'Fedora', operatingsystemrelease: 'Rawhide', + operatingsystemmajrelease: 'Rawhide', path: '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', } end @@ -142,7 +146,8 @@ kernel: 'Linux', osfamily: 'Gentoo', operatingsystem: 'Gentoo', - operatingsystemrelease: '3.16.1-gentoo', + operatingsystemrelease: '2.7', + operatingsystemmajrelease: '2.7', path: '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/opt/bin', } end