Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(#168) Handling a missing /etc/localtime file instead of breaking #169

Merged
merged 6 commits into from
Dec 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
* Wed Dec 06 2023 Mike Riddle <[email protected]> - 6.17.1
- The module will now correctly handle a situation where /etc/localtime doesn't exist

* Mon Oct 23 2023 Steven Pritchard <[email protected]> - 6.17.0
- [puppetsync] Add EL9 support

Expand Down
18 changes: 18 additions & 0 deletions lib/facter/timezone_file.rb
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion manifests/server.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion metadata.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
15 changes: 15 additions & 0 deletions spec/acceptance/suites/default/00_default_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 4 additions & 2 deletions spec/classes/server_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading