From 349a2c79edbb23337940d338385c56431812ff3d Mon Sep 17 00:00:00 2001 From: Steven Pritchard Date: Mon, 15 Jul 2024 16:22:04 -0500 Subject: [PATCH] Fix use of legacy facts --- README.md | 6 +++--- lib/facter/nginx_version.rb | 2 +- manifests/params.pp | 2 +- spec/classes/nginx_spec.rb | 20 ++++++++++---------- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 8eb2f990e..fc7f006c3 100644 --- a/README.md +++ b/README.md @@ -347,7 +347,7 @@ define web::nginx_ssl_with_redirect ( $www_root = "${full_web_path}/${name}/", $location_cfg_append = undef, ) { - nginx::resource::server { "${name}.${::domain}": + nginx::resource::server { "${name}.${facts['networking']['domain']}": ensure => present, www_root => "${full_web_path}/${name}/", location_cfg_append => { @@ -361,7 +361,7 @@ define web::nginx_ssl_with_redirect ( $tmp_www_root = $www_root } - nginx::resource::server { "${name}.${::domain} ${name}": + nginx::resource::server { "${name}.${facts['networking']['domain']} ${name}": ensure => present, listen_port => 443, www_root => $tmp_www_root, @@ -379,7 +379,7 @@ define web::nginx_ssl_with_redirect ( ensure => present, ssl => true, ssl_only => true, - server => "${name}.${::domain} ${name}", + server => "${name}.${facts['networking']['domain']} ${name}", www_root => "${full_web_path}/${name}/", location => '~ \.php$', index_files => ['index.php', 'index.html', 'index.htm'], diff --git a/lib/facter/nginx_version.rb b/lib/facter/nginx_version.rb index 8eb60591f..c8b13704c 100644 --- a/lib/facter/nginx_version.rb +++ b/lib/facter/nginx_version.rb @@ -2,7 +2,7 @@ Facter.add(:nginx_version) do confine { Facter.value(:kernel) != 'windows' } - confine { Facter.value(:operatingsystem) != 'nexus' } + confine { Facter.value(:os)['name'] != 'nexus' } setcode do if Facter::Util::Resolution.which('nginx') || Facter::Util::Resolution.which('openresty') nginx_version_command = Facter::Util::Resolution.which('nginx') ? 'nginx -v 2>&1' : 'openresty -v 2>&1' diff --git a/manifests/params.pp b/manifests/params.pp index 57cfce057..412d8c623 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -185,7 +185,7 @@ } } default: { - ## For cases not covered in $::osfamily + ## For cases not covered in $facts['os']['family'] case $facts['os']['name'] { default: { $_module_os_overrides = {} } } diff --git a/spec/classes/nginx_spec.rb b/spec/classes/nginx_spec.rb index 916f074d4..016dbdf45 100644 --- a/spec/classes/nginx_spec.rb +++ b/spec/classes/nginx_spec.rb @@ -41,14 +41,14 @@ context 'nginx::package' do it { is_expected.to compile.with_all_deps } - case facts[:osfamily] + case facts[:os]['family'] when 'RedHat' context 'using defaults' do it { is_expected.to contain_package('nginx') } it do is_expected.to contain_yumrepo('nginx-release').with( - 'baseurl' => "https://nginx.org/packages/#{%w[CentOS VirtuozzoLinux OracleLinux].include?(facts[:operatingsystem]) ? 'centos' : 'rhel'}/#{facts[:operatingsystemmajrelease]}/$basearch/", + 'baseurl' => "https://nginx.org/packages/#{%w[CentOS VirtuozzoLinux OracleLinux].include?(facts[:os]['name']) ? 'centos' : 'rhel'}/#{facts[:os]['release']['major']}/$basearch/", 'descr' => 'nginx repo', 'enabled' => '1', 'gpgcheck' => '1', @@ -74,7 +74,7 @@ it do is_expected.to contain_yumrepo('nginx-release').with( - 'baseurl' => "https://nginx.org/packages/#{%w[CentOS VirtuozzoLinux OracleLinux].include?(facts[:operatingsystem]) ? 'centos' : 'rhel'}/#{facts[:operatingsystemmajrelease]}/$basearch/", + 'baseurl' => "https://nginx.org/packages/#{%w[CentOS VirtuozzoLinux OracleLinux].include?(facts[:os]['name']) ? 'centos' : 'rhel'}/#{facts[:os]['release']['major']}/$basearch/", 'descr' => 'nginx repo', 'enabled' => '1', 'gpgcheck' => '1', @@ -91,7 +91,7 @@ it do is_expected.to contain_yumrepo('nginx-release').with( - 'baseurl' => "https://nginx.org/packages/mainline/#{%w[CentOS VirtuozzoLinux OracleLinux].include?(facts[:operatingsystem]) ? 'centos' : 'rhel'}/#{facts[:operatingsystemmajrelease]}/$basearch/" + 'baseurl' => "https://nginx.org/packages/mainline/#{%w[CentOS VirtuozzoLinux OracleLinux].include?(facts[:os]['name']) ? 'centos' : 'rhel'}/#{facts[:os]['release']['major']}/$basearch/" ) end @@ -105,12 +105,12 @@ it { is_expected.to contain_yumrepo('passenger').that_comes_before('Package[nginx]') } end - context 'package_source => passenger', unless: facts[:operatingsystemmajrelease] == '8' do + context 'package_source => passenger', unless: facts[:os]['release']['major'] == '8' do let(:params) { { package_source: 'passenger' } } it do is_expected.to contain_yumrepo('passenger').with( - 'baseurl' => "https://oss-binaries.phusionpassenger.com/yum/passenger/el/#{facts[:operatingsystemmajrelease]}/$basearch", + 'baseurl' => "https://oss-binaries.phusionpassenger.com/yum/passenger/el/#{facts[:os]['release']['major']}/$basearch", 'gpgcheck' => '0', 'repo_gpgcheck' => '1', 'gpgkey' => 'https://oss-binaries.phusionpassenger.com/auto-software-signing-gpg-key.txt' @@ -128,7 +128,7 @@ it { is_expected.to contain_package('passenger').with('ensure' => 'installed') } end - describe 'installs the requested passenger package version', unless: facts[:operatingsystemmajrelease] == '8' do + describe 'installs the requested passenger package version', unless: facts[:os]['release']['major'] == '8' do let(:params) { { package_source: 'passenger', passenger_package_ensure: '4.1.0-1.el9' } } it 'installs specified version exactly' do @@ -158,7 +158,7 @@ it do is_expected.to contain_apt__source('nginx').with( - 'location' => "https://nginx.org/packages/#{facts[:operatingsystem].downcase}", + 'location' => "https://nginx.org/packages/#{facts[:os]['name'].downcase}", 'repos' => 'nginx', 'key' => { 'id' => '573BFD6B3D8FBC641079A6ABABF5BD827BD9BF62' } ) @@ -180,7 +180,7 @@ it do is_expected.to contain_apt__source('nginx').with( - 'location' => "https://nginx.org/packages/mainline/#{facts[:operatingsystem].downcase}" + 'location' => "https://nginx.org/packages/mainline/#{facts[:os]['name'].downcase}" ) end end @@ -358,7 +358,7 @@ end end - case facts[:osfamily] + case facts[:os]['family'] when 'RedHat' it { is_expected.to contain_file('/etc/nginx/nginx.conf').with_content %r{^user nginx;} }