diff --git a/CHANGELOG b/CHANGELOG index 6e643da..0e3b283 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,6 @@ +* Wed Dec 06 2023 Mike Riddle - 6.17.1 +- The module will now correctly handle a situation where /etc/localtime doesn't exist + * Mon Oct 23 2023 Steven Pritchard - 6.17.0 - [puppetsync] Add EL9 support diff --git a/lib/facter/timezone_file.rb b/lib/facter/timezone_file.rb new file mode 100644 index 0000000..007f7bc --- /dev/null +++ b/lib/facter/timezone_file.rb @@ -0,0 +1,18 @@ +# _Description_ +# +# Return the path for the timezone file the system is using +# +Facter.add(:timezone_file) do + confine kernel: :linux + setcode do + # If /etc/localtime doesn't exist, use the appropriate file in /usr/share/zoneinfo + timezone_file = if File.exist?('/etc/localtime') + '/etc/localtime' + elsif File.exist?("/usr/share/zoneinfo/#{Facter.value('timezone')}") + "/usr/share/zoneinfo/#{Facter.value('timezone')}" + else + '/usr/share/zoneinfo/UTC' + end + timezone_file + end +end diff --git a/manifests/server.pp b/manifests/server.pp index ea194f1..5ba9c86 100644 --- a/manifests/server.pp +++ b/manifests/server.pp @@ -38,7 +38,7 @@ } file { '/var/empty/sshd/etc/localtime': - source => 'file:///etc/localtime', + source => "file://${facts['timezone_file']}", owner => 'root', group => 'root', mode => '0644', diff --git a/metadata.json b/metadata.json index fb948c3..587ca0f 100644 --- a/metadata.json +++ b/metadata.json @@ -1,6 +1,6 @@ { "name": "simp-ssh", - "version": "6.17.0", + "version": "6.17.1", "author": "SIMP Team", "summary": "Manage ssh", "license": "Apache-2.0", diff --git a/spec/acceptance/suites/default/00_default_spec.rb b/spec/acceptance/suites/default/00_default_spec.rb index b336a76..cbbc182 100644 --- a/spec/acceptance/suites/default/00_default_spec.rb +++ b/spec/acceptance/suites/default/00_default_spec.rb @@ -308,6 +308,21 @@ expect(file_content_on(server, '/etc/ssh/sshd_config').strip).to_not match('AuthorizedKeysFile\s*/foo/bar') end end + + context 'with default parameters' do + it 'should move the /etc/localtime file temporarily if it exists' do + on(client, 'if [ -f /etc/localtime ]; then mv /etc/localtime /etc/localtime.bak; fi') + end + it 'should configure server with no errors when missing /etc/localtime' do + enable_epel_on(server) + enable_epel_on(client) + set_hieradata_on(server, server_hieradata) + apply_manifest_on(server, server_manifest, expect_failures: false) + end + it 'should move the /etc/localtime file back if it was moved' do + on(client, 'if [ -f /etc/localtime.bak ]; then mv /etc/localtime.bak /etc/localtime; fi') + end + end end end end diff --git a/spec/classes/server_spec.rb b/spec/classes/server_spec.rb index 4197614..8482f2a 100644 --- a/spec/classes/server_spec.rb +++ b/spec/classes/server_spec.rb @@ -66,9 +66,11 @@ on_supported_os.each do |os, os_facts| context "on #{os}" do let(:facts) do - os_facts + os_facts.merge( + openssh_version: '6.6', + timezone_file: '/etc/localtime', + ) end - let(:facts) { os_facts.merge( { :openssh_version => '6.6' } ) } context "with default parameters" do it_behaves_like "an ssh server", os_facts