From c155137eddfd3522e062ed246ef75ac10281e2ac Mon Sep 17 00:00:00 2001 From: Kenyon Ralph Date: Fri, 24 Dec 2021 21:13:34 -0800 Subject: [PATCH] remove params.pp, use hiera data instead --- data/Archlinux.yaml | 9 +++++ data/Gentoo.yaml | 5 +++ data/RedHat.yaml | 5 +++ data/Suse.yaml | 5 +++ hiera.yaml | 7 ++++ manifests/init.pp | 26 +++++++------- manifests/params.pp | 67 ------------------------------------- spec/classes/chrony_spec.rb | 37 ++++---------------- 8 files changed, 51 insertions(+), 110 deletions(-) create mode 100644 data/Archlinux.yaml create mode 100644 data/Gentoo.yaml create mode 100644 data/RedHat.yaml create mode 100644 data/Suse.yaml create mode 100644 hiera.yaml delete mode 100644 manifests/params.pp diff --git a/data/Archlinux.yaml b/data/Archlinux.yaml new file mode 100644 index 0000000..11ed31a --- /dev/null +++ b/data/Archlinux.yaml @@ -0,0 +1,9 @@ +--- +chrony::clientlog: true +chrony::cmdacl: + - cmdallow 127.0.0.1 +chrony::config_keys_mode: '0644' +chrony::config_keys: /etc/chrony.keys +chrony::config: /etc/chrony.conf +chrony::dumpdir: /var/lib/chrony +chrony::rtconutc: true diff --git a/data/Gentoo.yaml b/data/Gentoo.yaml new file mode 100644 index 0000000..cc961ad --- /dev/null +++ b/data/Gentoo.yaml @@ -0,0 +1,5 @@ +--- +chrony::clientlog: true +chrony::config_keys_mode: '0644' +chrony::package_name: net-misc/chrony +chrony::rtconutc: true diff --git a/data/RedHat.yaml b/data/RedHat.yaml new file mode 100644 index 0000000..84725d4 --- /dev/null +++ b/data/RedHat.yaml @@ -0,0 +1,5 @@ +--- +chrony::config_keys_group: chrony +chrony::config_keys: /etc/chrony.keys +chrony::config: /etc/chrony.conf +chrony::wait_manage: true diff --git a/data/Suse.yaml b/data/Suse.yaml new file mode 100644 index 0000000..84725d4 --- /dev/null +++ b/data/Suse.yaml @@ -0,0 +1,5 @@ +--- +chrony::config_keys_group: chrony +chrony::config_keys: /etc/chrony.keys +chrony::config: /etc/chrony.conf +chrony::wait_manage: true diff --git a/hiera.yaml b/hiera.yaml new file mode 100644 index 0000000..b3a6729 --- /dev/null +++ b/hiera.yaml @@ -0,0 +1,7 @@ +--- +version: 5 + +hierarchy: + - name: OS family + paths: + - '%{facts.os.family}.yaml' diff --git a/manifests/init.pp b/manifests/init.pp index 68e7690..8e31a21 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -207,24 +207,24 @@ Array[Stdlib::IP::Address] $bindaddress = [], Array[String] $bindcmdaddress = ['127.0.0.1', '::1'], Optional[String] $initstepslew = undef, - Array[String] $cmdacl = $chrony::params::cmdacl, + Array[String] $cmdacl = [], Optional[Stdlib::Port] $cmdport = undef, $commandkey = 0, - Stdlib::Unixpath $config = $chrony::params::config, + Stdlib::Unixpath $config = '/etc/chrony/chrony.conf', String[1] $config_template = 'chrony/chrony.conf.epp', - Stdlib::Unixpath $config_keys = $chrony::params::config_keys, + Stdlib::Unixpath $config_keys = '/etc/chrony/chrony.keys', String[1] $config_keys_template = 'chrony/chrony.keys.epp', String[1] $chrony_password = 'xyzzy', - Variant[Integer[0],String[1]] $config_keys_owner = $chrony::params::config_keys_owner, - Variant[Integer[0],String[1]] $config_keys_group = $chrony::params::config_keys_group, - Stdlib::Filemode $config_keys_mode = $chrony::params::config_keys_mode, + Variant[Integer[0],String[1]] $config_keys_owner = 0, + Variant[Integer[0],String[1]] $config_keys_group = 0, + Stdlib::Filemode $config_keys_mode = '0640', Boolean $config_keys_manage = true, Array[String[1]] $keys = [], Stdlib::Unixpath $driftfile = '/var/lib/chrony/drift', Variant[Boolean[false],Integer[1,15]] $local_stratum = 10, Optional[String[1]] $log_options = undef, String[1] $package_ensure = 'present', - String[1] $package_name = $chrony::params::package_name, + String[1] $package_name = 'chrony', Optional[String] $package_source = undef, Optional[String] $package_provider = undef, $refclocks = [], @@ -243,15 +243,15 @@ Float $threshold = 0.5, Boolean $lock_all = false, Optional[Stdlib::Port] $port = undef, - Boolean $clientlog = $chrony::params::clientlog, + Boolean $clientlog = false, Optional[Integer] $clientloglimit = undef, Boolean $service_enable = true, Stdlib::Ensure::Service $service_ensure = 'running', Boolean $service_manage = true, - String[1] $service_name = $chrony::params::service_name, + String[1] $service_name = 'chronyd', Boolean $wait_enable = false, Stdlib::Ensure::Service $wait_ensure = 'stopped', - Boolean $wait_manage = $chrony::params::wait_manage, + Boolean $wait_manage = false, String[1] $wait_name = 'chrony-wait.service', Optional[String] $smoothtime = undef, Optional[Enum['system', 'step', 'slew', 'ignore']] $leapsecmode = undef, @@ -261,10 +261,10 @@ Optional[Float] $maxupdateskew = undef, Optional[Numeric] $stratumweight = undef, Boolean $rtcsync = true, - Boolean $rtconutc = $chrony::params::rtconutc, + Boolean $rtconutc = false, Variant[Hash,Array[String]] $hwtimestamps = [], - Optional[Stdlib::Unixpath] $dumpdir = $chrony::params::dumpdir, -) inherits chrony::params { + Optional[Stdlib::Unixpath] $dumpdir = undef, +) { if ! $config_keys_manage and $chrony_password != 'unset' { fail("Setting \$config_keys_manage false and \$chrony_password at same time in ${module_name} is not possible.") } diff --git a/manifests/params.pp b/manifests/params.pp deleted file mode 100644 index 91c7231..0000000 --- a/manifests/params.pp +++ /dev/null @@ -1,67 +0,0 @@ -# @summary chrony class parameters -# -# @api private -class chrony::params { - case $facts['os']['family'] { - 'Archlinux' : { - $package_name = 'chrony' - $cmdacl = ['cmdallow 127.0.0.1'] - $config = '/etc/chrony.conf' - $config_keys = '/etc/chrony.keys' - $config_keys_owner = 0 - $config_keys_group = 0 - $config_keys_mode = '0644' - $service_name = 'chronyd' - $wait_manage = false - $clientlog = true - $rtconutc = true - $dumpdir = '/var/lib/chrony' - } - 'Gentoo' : { - $package_name = 'net-misc/chrony' - $cmdacl = [] - $config = '/etc/chrony/chrony.conf' - $config_keys = '/etc/chrony/chrony.keys' - $config_keys_owner = 0 - $config_keys_group = 0 - $config_keys_mode = '0644' - $service_name = 'chronyd' - $wait_manage = false - $clientlog = true - $rtconutc = true - $dumpdir = undef - } - 'Suse', 'RedHat' : { - $package_name = 'chrony' - $cmdacl = [] - $config = '/etc/chrony.conf' - $config_keys = '/etc/chrony.keys' - $config_keys_owner = 0 - $config_keys_group = chrony - $config_keys_mode = '0640' - $service_name = 'chronyd' - $wait_manage = true - $clientlog = false - $rtconutc = false - $dumpdir = undef - } - 'Debian' : { - $package_name = 'chrony' - $cmdacl = [] - $config = '/etc/chrony/chrony.conf' - $config_keys = '/etc/chrony/chrony.keys' - $config_keys_owner = 0 - $config_keys_group = 0 - $config_keys_mode = '0640' - $service_name = 'chrony' - $wait_manage = false - $clientlog = false - $rtconutc = false - $dumpdir = undef - } - - default : { - fail("The ${module_name} module is not supported on an ${facts['os']['family']} based system.") - } - } -} diff --git a/spec/classes/chrony_spec.rb b/spec/classes/chrony_spec.rb index c8bfffc..bb8201b 100644 --- a/spec/classes/chrony_spec.rb +++ b/spec/classes/chrony_spec.rb @@ -4,16 +4,6 @@ # rubocop:disable RSpec/EmptyExampleGroup describe 'chrony' do - context 'on any other system' do - let(:facts) do - { - os: { family: 'UnsupportedOS' } - } - end - - it { is_expected.to raise_error(%r{The chrony module is not supported on an UnsupportedOS based system\.}) } - end - on_supported_os.each do |os, facts| context "on #{os}" do let(:facts) do @@ -42,7 +32,6 @@ context 'with defaults' do it { is_expected.to compile.with_all_deps } it { is_expected.to contain_class('chrony') } - it { is_expected.to contain_class('chrony::params') } it { is_expected.to contain_class('chrony::install').that_comes_before('Class[chrony::config]') } it { is_expected.to contain_class('chrony::config').that_notifies('Class[chrony::service]') } it { is_expected.to contain_class('chrony::service') } @@ -470,7 +459,7 @@ end context 'chrony::service' do - let :params do + let(:params) do { service_ensure: 'running', service_enable: true, @@ -496,24 +485,12 @@ end end - case facts[:os]['family'] - when 'Archlinux', 'RedHat', 'Gentoo' - context 'using defaults' do - it do - is_expected.to contain_service('chronyd').with( - ensure: 'running', - enable: true - ) - end - end - when 'Debian' - context 'using defaults' do - it do - is_expected.to contain_service('chrony').with( - ensure: 'running', - enable: true - ) - end + context 'using defaults' do + it do + is_expected.to contain_service('chronyd').with( + ensure: 'running', + enable: true + ) end end end