From 0dd501008a57a0e1afb01813e6ba5dbfe01b2494 Mon Sep 17 00:00:00 2001 From: Kjetil Torgrim Homme Date: Thu, 12 Jun 2025 13:27:48 +0200 Subject: [PATCH 1/6] split tests for Debian and Ubuntu relying on Ubuntu full containing the month number works fine for specific versions, but makes it hard to use versioncmp. this patch does not change behaviour --- manifests/config.pp | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/manifests/config.pp b/manifests/config.pp index e2865c74..741b8f01 100644 --- a/manifests/config.pp +++ b/manifests/config.pp @@ -33,10 +33,22 @@ } } 'Debian': { - if $facts['os']['release']['major'] == '12' { - $daemon_config = '/etc/ntpsec/ntp.conf' + if $facts['os']['name'] == 'Ubuntu' { + if $ntp::user and $facts['os']['release']['major'] == '18.04' { + file_line { 'Set NTPD daemon user': + ensure => present, + path => '/usr/lib/ntp/ntp-systemd-wrapper', + line => "RUNASUSER=${ntp::user}", + match => '^RUNASUSER\=', + } + } } else { - $daemon_config = '/etc/default/ntp' + # Assume all other distros in Debian family follow Debian version numbering + if versioncmp($facts['os']['release']['full'], '12') >= 0 { + $daemon_config = '/etc/ntpsec/ntp.conf' + } else { + $daemon_config = '/etc/default/ntp' + } } if $ntp::daemon_extra_opts { file_line { 'Set NTPD daemon options': @@ -46,14 +58,6 @@ match => '^NTPD_OPTS\=', } } - if $ntp::user and $facts['os']['release']['major'] == '18.04' { - file_line { 'Set NTPD daemon user': - ensure => present, - path => '/usr/lib/ntp/ntp-systemd-wrapper', - line => "RUNASUSER=${ntp::user}", - match => '^RUNASUSER\=', - } - } } 'Suse': { $daemon_config = '/etc/sysconfig/ntp' From 283fd3fe627eddc47f110749d54c4ffa944765e1 Mon Sep 17 00:00:00 2001 From: Kjetil Torgrim Homme Date: Thu, 12 Jun 2025 13:33:59 +0200 Subject: [PATCH 2/6] ntp::user needs this code also on Ubuntu 20.04 and 22.04 --- manifests/config.pp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/manifests/config.pp b/manifests/config.pp index 741b8f01..569436f0 100644 --- a/manifests/config.pp +++ b/manifests/config.pp @@ -34,7 +34,11 @@ } 'Debian': { if $facts['os']['name'] == 'Ubuntu' { - if $ntp::user and $facts['os']['release']['major'] == '18.04' { + # This ugly indentation is forced upon me by puppet-lint. I disclaim + # any responsibility for damage to your eyes. + if (versioncmp($facts['os']['release']['major'], '18.04') >= 0 and + versioncmp($facts['os']['release']['major'], '24.04') < 0 and + $ntp::user) { file_line { 'Set NTPD daemon user': ensure => present, path => '/usr/lib/ntp/ntp-systemd-wrapper', From b6c368b211c749ccc77031e78d2531fa75134625 Mon Sep 17 00:00:00 2001 From: Kjetil Torgrim Homme Date: Thu, 12 Jun 2025 13:37:57 +0200 Subject: [PATCH 3/6] use ntpsec package on Debian 12 and Ubuntu 24.04 both of these have "ntp" as a transitional package which installs "ntpsec", but setting package_name explicitly is cleaner and allows easier keying of how to configure the system. --- data/Debian-12.yaml | 4 ++++ data/Ubuntu-24.04.yaml | 4 ++++ manifests/config.pp | 10 ++++------ metadata.json | 3 ++- 4 files changed, 14 insertions(+), 7 deletions(-) create mode 100644 data/Debian-12.yaml create mode 100644 data/Ubuntu-24.04.yaml diff --git a/data/Debian-12.yaml b/data/Debian-12.yaml new file mode 100644 index 00000000..0b82489a --- /dev/null +++ b/data/Debian-12.yaml @@ -0,0 +1,4 @@ +--- +ntp::package_name: + - ntpsec +ntp::config: '/etc/ntpsec/ntp.conf' diff --git a/data/Ubuntu-24.04.yaml b/data/Ubuntu-24.04.yaml new file mode 100644 index 00000000..0b82489a --- /dev/null +++ b/data/Ubuntu-24.04.yaml @@ -0,0 +1,4 @@ +--- +ntp::package_name: + - ntpsec +ntp::config: '/etc/ntpsec/ntp.conf' diff --git a/manifests/config.pp b/manifests/config.pp index 569436f0..c480f5e8 100644 --- a/manifests/config.pp +++ b/manifests/config.pp @@ -46,13 +46,11 @@ match => '^RUNASUSER\=', } } + } + if 'ntpsec' in $ntp::package_name { + $daemon_config = '/etc/ntpsec/ntp.conf' } else { - # Assume all other distros in Debian family follow Debian version numbering - if versioncmp($facts['os']['release']['full'], '12') >= 0 { - $daemon_config = '/etc/ntpsec/ntp.conf' - } else { - $daemon_config = '/etc/default/ntp' - } + $daemon_config = '/etc/default/ntp' } if $ntp::daemon_extra_opts { file_line { 'Set NTPD daemon options': diff --git a/metadata.json b/metadata.json index cbf77954..9425a5fe 100644 --- a/metadata.json +++ b/metadata.json @@ -58,7 +58,8 @@ "operatingsystemrelease": [ "18.04", "20.04", - "22.04" + "22.04", + "24.04" ] }, { From c7f93cba7cec95bf251a180c2cdab68a6f9d0019 Mon Sep 17 00:00:00 2001 From: Kjetil Torgrim Homme Date: Thu, 12 Jun 2025 14:54:42 +0200 Subject: [PATCH 4/6] daemon_config is not ntp.conf, but the environment file for the service --- manifests/config.pp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manifests/config.pp b/manifests/config.pp index c480f5e8..b2191b3a 100644 --- a/manifests/config.pp +++ b/manifests/config.pp @@ -48,7 +48,7 @@ } } if 'ntpsec' in $ntp::package_name { - $daemon_config = '/etc/ntpsec/ntp.conf' + $daemon_config = '/etc/default/ntpsec' } else { $daemon_config = '/etc/default/ntp' } From b432117f595a1a4c4d6a7bc1d68ed9492103d545 Mon Sep 17 00:00:00 2001 From: Kjetil Torgrim Homme Date: Thu, 12 Jun 2025 18:01:32 +0200 Subject: [PATCH 5/6] update testing to know conf_path is different for new Debian and Ubuntu --- spec/classes/ntp_spec.rb | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/spec/classes/ntp_spec.rb b/spec/classes/ntp_spec.rb index 6051de8c..ca267157 100644 --- a/spec/classes/ntp_spec.rb +++ b/spec/classes/ntp_spec.rb @@ -9,6 +9,10 @@ let(:conf_path) do if os.include?('solaris') '/etc/inet/ntp.conf' + elsif f[:os]['name'] == 'Debian' && f[:os]['release']['major'].to_f >= 12 + '/etc/ntpsec/ntp.conf' + elsif f[:os]['name'] == 'Ubuntu' && f[:os]['release']['major'].to_f >= 24.04 + '/etc/ntpsec/ntp.conf' else '/etc/ntp.conf' end @@ -132,7 +136,7 @@ case f[:os]['family'] when 'RedHat' it 'uses the centos ntp servers' do - expect(subject).to contain_file('/etc/ntp.conf').with('content' => %r{server \d.centos.pool.ntp.org}) + expect(subject).to contain_file(conf_path).with('content' => %r{server \d.centos.pool.ntp.org}) end it do @@ -140,15 +144,15 @@ end when 'Debian' it 'uses the debian ntp servers' do - expect(subject).to contain_file('/etc/ntp.conf').with('content' => %r{server \d.debian.pool.ntp.org iburst\n}) + expect(subject).to contain_file(conf_path).with('content' => %r{server \d.debian.pool.ntp.org iburst\n}) end when 'Suse' it 'uses the opensuse ntp servers' do - expect(subject).to contain_file('/etc/ntp.conf').with('content' => %r{server \d.opensuse.pool.ntp.org}) + expect(subject).to contain_file(conf_path).with('content' => %r{server \d.opensuse.pool.ntp.org}) end when 'FreeBSD' it 'uses the freebsd ntp servers' do - expect(subject).to contain_file('/etc/ntp.conf').with('content' => %r{server \d.freebsd.pool.ntp.org iburst maxpoll 9}) + expect(subject).to contain_file(conf_path).with('content' => %r{server \d.freebsd.pool.ntp.org iburst maxpoll 9}) end when 'Solaris' it 'uses the generic NTP pool servers' do @@ -156,7 +160,7 @@ end when 'AIX' it 'uses the generic NTP pool servers on AIX' do - expect(subject).to contain_file('/etc/ntp.conf').with('content' => %r{server \d.pool.ntp.org}) + expect(subject).to contain_file(conf_path).with('content' => %r{server \d.pool.ntp.org}) end else it { From 018b0312e0b75e90f9e733533dec8d1ed9653520 Mon Sep 17 00:00:00 2001 From: Shubham Shinde Date: Thu, 17 Jul 2025 11:28:50 +0530 Subject: [PATCH 6/6] Fix specs and don't pass 'daemon_extra_opts' to ubuntu-24.04 --- spec/acceptance/ntp_parameters_spec.rb | 2 ++ spec/acceptance/ntp_user_and_daemon_opts_spec.rb | 13 +++++++++---- spec/acceptance/preferred_servers_spec.rb | 2 ++ 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/spec/acceptance/ntp_parameters_spec.rb b/spec/acceptance/ntp_parameters_spec.rb index 1b4161d0..8b23b8de 100644 --- a/spec/acceptance/ntp_parameters_spec.rb +++ b/spec/acceptance/ntp_parameters_spec.rb @@ -24,6 +24,8 @@ config = if os[:family] == 'solaris' '/etc/inet/ntp.conf' + elsif os[:family] == 'ubuntu' && os[:release].start_with?('24') + '/etc/ntpsec/ntp.conf' else '/etc/ntp.conf' end diff --git a/spec/acceptance/ntp_user_and_daemon_opts_spec.rb b/spec/acceptance/ntp_user_and_daemon_opts_spec.rb index 9c3cf81e..7503c8dd 100644 --- a/spec/acceptance/ntp_user_and_daemon_opts_spec.rb +++ b/spec/acceptance/ntp_user_and_daemon_opts_spec.rb @@ -29,21 +29,26 @@ '/etc/sysconfig/ntp' elsif os[:family] == 'debian' && os[:release].start_with?('12') '/etc/ntpsec/ntp.conf' + elsif os[:family] == 'ubuntu' && os[:release].start_with?('24') + '/etc/default/ntpsec' else '/etc/default/ntp' end -if os[:family] == 'debian' && os[:release].start_with?('12') +if os[:family] == 'debian' && os[:release].to_i >= 12 ntpd_opts_match = %r{(OPTIONS|NTPD_OPTS)='-g -i /var/lib/ntpsec'} - chroot_dir = '/var/lib/ntpsec' + chroot_opt = '-i /var/lib/ntpsec' +elsif os[:family] == 'ubuntu' && os[:release].to_f >= 24.04 + ntpd_opts_match = %r{(OPTIONS|NTPD_OPTS)='-g '} + chroot_opt = '' else ntpd_opts_match = %r{(OPTIONS|NTPD_OPTS)='-g -i /var/lib/ntp'} - chroot_dir = '/var/lib/ntp' + chroot_opt = '-i /var/lib/ntp' end describe 'ntp class with daemon options:', unless: UNSUPPORTED_PLATFORMS.include?(os[:family]) || (os[:release].start_with?('5') && os[:family] == 'redhat') do let(:pp) do - "class { 'ntp': service_enable => true, service_ensure => running, service_manage => true, service_name => '#{servicename}', user => 'ntp', daemon_extra_opts => '-g -i #{chroot_dir}' }" + "class { 'ntp': service_enable => true, service_ensure => running, service_manage => true, service_name => '#{servicename}', user => 'ntp', daemon_extra_opts => '-g #{chroot_opt}' }" end context 'when run' do diff --git a/spec/acceptance/preferred_servers_spec.rb b/spec/acceptance/preferred_servers_spec.rb index b4854bbe..3ae7758a 100644 --- a/spec/acceptance/preferred_servers_spec.rb +++ b/spec/acceptance/preferred_servers_spec.rb @@ -4,6 +4,8 @@ config = if os[:family] == 'solaris' '/etc/inet/ntp.conf' + elsif os[:family] == 'ubuntu' && os[:release].start_with?('24') + '/etc/ntpsec/ntp.conf' else '/etc/ntp.conf' end