From db6dd1b89014f5c2139f8d78a9b737d804c1d51e Mon Sep 17 00:00:00 2001 From: Christoph Maser Date: Sun, 6 Oct 2024 14:31:19 +0200 Subject: [PATCH] add version defaults for Debian, Ubuntu and RedHat (clones) As discussed before there is an issue with the nginx_version. If the nginx package is not yet installed on a system the fact `nginx_version` is not set. In that case the hard coded default value of `1.16.0` is used. This change will add a default version for some operating systems via hiera data. This avoid the need to run puppet twice to get the correct configuration generated. --- data/common.yaml | 3 +++ data/os/Debian/11.yaml | 3 +++ data/os/Debian/12.yaml | 3 +++ data/os/RedHat/8.yaml | 3 +++ data/os/RedHat/9.yaml | 3 +++ data/os/Ubuntu/20.04.yaml | 3 +++ data/os/Ubuntu/22.04.yaml | 3 +++ hiera.yaml | 21 +++++++++++++++++++++ spec/defines/resource_server_spec.rb | 8 ++++---- 9 files changed, 46 insertions(+), 4 deletions(-) create mode 100644 data/common.yaml create mode 100644 data/os/Debian/11.yaml create mode 100644 data/os/Debian/12.yaml create mode 100644 data/os/RedHat/8.yaml create mode 100644 data/os/RedHat/9.yaml create mode 100644 data/os/Ubuntu/20.04.yaml create mode 100644 data/os/Ubuntu/22.04.yaml create mode 100644 hiera.yaml diff --git a/data/common.yaml b/data/common.yaml new file mode 100644 index 000000000..31dda199e --- /dev/null +++ b/data/common.yaml @@ -0,0 +1,3 @@ +--- + +{} diff --git a/data/os/Debian/11.yaml b/data/os/Debian/11.yaml new file mode 100644 index 000000000..5767ad622 --- /dev/null +++ b/data/os/Debian/11.yaml @@ -0,0 +1,3 @@ +--- + +nginx::nginx_version: '1.18.0' diff --git a/data/os/Debian/12.yaml b/data/os/Debian/12.yaml new file mode 100644 index 000000000..faaa42821 --- /dev/null +++ b/data/os/Debian/12.yaml @@ -0,0 +1,3 @@ +--- + +nginx::nginx_version: '1.22.1' diff --git a/data/os/RedHat/8.yaml b/data/os/RedHat/8.yaml new file mode 100644 index 000000000..bc24cf7f4 --- /dev/null +++ b/data/os/RedHat/8.yaml @@ -0,0 +1,3 @@ +--- + +nginx::nginx_version: '1.14.1' diff --git a/data/os/RedHat/9.yaml b/data/os/RedHat/9.yaml new file mode 100644 index 000000000..dee2ff0c0 --- /dev/null +++ b/data/os/RedHat/9.yaml @@ -0,0 +1,3 @@ +--- + +nginx::nginx_version: '1.20.1' diff --git a/data/os/Ubuntu/20.04.yaml b/data/os/Ubuntu/20.04.yaml new file mode 100644 index 000000000..5767ad622 --- /dev/null +++ b/data/os/Ubuntu/20.04.yaml @@ -0,0 +1,3 @@ +--- + +nginx::nginx_version: '1.18.0' diff --git a/data/os/Ubuntu/22.04.yaml b/data/os/Ubuntu/22.04.yaml new file mode 100644 index 000000000..5767ad622 --- /dev/null +++ b/data/os/Ubuntu/22.04.yaml @@ -0,0 +1,3 @@ +--- + +nginx::nginx_version: '1.18.0' diff --git a/hiera.yaml b/hiera.yaml new file mode 100644 index 000000000..545fff327 --- /dev/null +++ b/hiera.yaml @@ -0,0 +1,21 @@ +--- +version: 5 + +defaults: # Used for any hierarchy level that omits these keys. + datadir: data # This path is relative to hiera.yaml's directory. + data_hash: yaml_data # Use the built-in YAML backend. + +hierarchy: + - name: "osfamily/major release" + paths: + # Used to distinguish between Debian and Ubuntu + - "os/%{facts.os.name}/%{facts.os.release.major}.yaml" + - "os/%{facts.os.family}/%{facts.os.release.major}.yaml" + # Used for Solaris + - "os/%{facts.os.family}/%{facts.kernelrelease}.yaml" + - name: "osfamily" + paths: + - "os/%{facts.os.name}.yaml" + - "os/%{facts.os.family}.yaml" + - name: 'common' + path: 'common.yaml' diff --git a/spec/defines/resource_server_spec.rb b/spec/defines/resource_server_spec.rb index 8a221db56..d0595e78d 100644 --- a/spec/defines/resource_server_spec.rb +++ b/spec/defines/resource_server_spec.rb @@ -688,19 +688,19 @@ end context 'with fact nginx_version=1.14.1' do - let(:facts) { facts.merge(nginx_version: '1.14.1') } + let(:pre_condition) { 'class {"nginx": nginx_version => "1.14.1"}' } it { is_expected.to contain_concat__fragment("#{title}-ssl-header").with_content(%r{ ssl on;}) } end context 'with fact nginx_version=1.15.1' do - let(:facts) { facts.merge(nginx_version: '1.15.1') } + let(:pre_condition) { 'class {"nginx": nginx_version => "1.15.1"}' } it { is_expected.to contain_concat__fragment("#{title}-ssl-header").without_content(%r{ ssl on;}) } end context 'http2 on with fact nginx_version=1.25.1' do - let(:facts) { facts.merge(nginx_version: '1.25.1') } + let(:pre_condition) { 'class {"nginx": nginx_version => "1.25.1"}' } let :params do default_params.merge( http2: 'on', @@ -714,7 +714,7 @@ end context 'with fact nginx_version=1.25.1' do - let(:facts) { facts.merge(nginx_version: '1.25.1') } + let(:pre_condition) { 'class {"nginx": nginx_version => "1.25.1"}' } it { is_expected.to contain_concat__fragment("#{title}-ssl-header").with_content(%r{^\s+http2\s+off;}) } end