Skip to content

Commit ebf71e0

Browse files
authored
Merge pull request #419 from treydock/fixes
Notify sshd when conf.d files change
2 parents 83037ef + a343a67 commit ebf71e0

File tree

9 files changed

+31
-9
lines changed

9 files changed

+31
-9
lines changed

manifests/config_file_server.pp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,6 @@
4343
group => $group,
4444
mode => $mode,
4545
content => epp('ssh/config_file.epp', { 'lines' => $lines, 'custom' => $custom }),
46+
notify => $ssh::server::notify_service,
4647
}
4748
}

manifests/server.pp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -605,6 +605,12 @@
605605
$packages_require = undef
606606
}
607607

608+
if $manage_service {
609+
$notify_service = Service['sshd_service']
610+
} else {
611+
$notify_service = undef
612+
}
613+
608614
file { 'sshd_config' :
609615
ensure => file,
610616
path => $config_path,
@@ -626,7 +632,7 @@
626632
recurse => $include_dir_purge,
627633
force => $include_dir_purge,
628634
require => $packages_require,
629-
notify => Service['sshd_service'],
635+
notify => $notify_service,
630636
}
631637
} else {
632638
$include_dir = undef

spec/classes/server_spec.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@
106106
purge: 'true',
107107
recurse: 'true',
108108
force: 'true',
109+
notify: 'Service[sshd_service]',
109110
)
110111
end
111112
else
@@ -143,7 +144,7 @@
143144
supported_os: [
144145
{
145146
'operatingsystem' => 'RedHat',
146-
'operatingsystemrelease' => ['7'],
147+
'operatingsystemrelease' => ['8'],
147148
},
148149
],
149150
}

spec/defines/config_file_server_spec.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,25 @@
3131
'group' => 'root',
3232
'mode' => '0600',
3333
'content' => content_header,
34+
'notify' => 'Service[sshd_service]',
3435
},
3536
)
3637
end
3738
end
3839

40+
context 'when not managing the sshd service' do
41+
let(:pre_condition) do
42+
<<-PP
43+
class { 'ssh::server':
44+
manage_service => false,
45+
}
46+
PP
47+
end
48+
49+
it { is_expected.to compile.with_all_deps }
50+
it { is_expected.to contain_file('/etc/ssh/sshd_config.d/ing.conf').without_notify }
51+
end
52+
3953
context "on #{os} with ensure set to valid value" do
4054
let(:params) { { ensure: 'absent' } }
4155

spec/fixtures/testing/Debian-11_sshd_config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
#
44
# See https://man.openbsd.org/sshd_config for more info
55

6+
Include /etc/ssh/sshd_config.d/*.conf
67
AcceptEnv LANG
78
AcceptEnv LC_*
8-
Include /etc/ssh/sshd_config.d/*.conf
99
KbdInteractiveAuthentication no
1010
PrintMotd no
1111
Subsystem sftp /usr/lib/openssh/sftp-server

spec/fixtures/testing/RedHat-9_sshd_config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
#
44
# See https://man.openbsd.org/sshd_config for more info
55

6-
AuthorizedKeysFile .ssh/authorized_keys
76
Include /etc/ssh/sshd_config.d/*.conf
7+
AuthorizedKeysFile .ssh/authorized_keys
88
Subsystem sftp /usr/libexec/openssh/sftp-server

spec/fixtures/testing/Ubuntu-20.04_sshd_config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#
44
# See https://man.openbsd.org/sshd_config for more info
55

6+
Include /etc/ssh/sshd_config.d/*.conf
67
AcceptEnv LANG
78
AcceptEnv LC_ADDRESS
89
AcceptEnv LC_ALL
@@ -27,7 +28,6 @@ GSSAPICleanupCredentials yes
2728
HostbasedAuthentication no
2829
IgnoreRhosts yes
2930
IgnoreUserKnownHosts no
30-
Include /etc/ssh/sshd_config.d/*.conf
3131
KbdInteractiveAuthentication yes
3232
LoginGraceTime 120
3333
PasswordAuthentication yes

spec/fixtures/testing/Ubuntu-22.04_sshd_config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
#
44
# See https://man.openbsd.org/sshd_config for more info
55

6+
Include /etc/ssh/sshd_config.d/*.conf
67
AcceptEnv LANG
78
AcceptEnv LC_*
8-
Include /etc/ssh/sshd_config.d/*.conf
99
KbdInteractiveAuthentication no
1010
PasswordAuthentication yes
1111
PrintMotd no

templates/sshd_config.erb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
#
44
# See https://man.openbsd.org/sshd_config for more info
55

6+
<% if @include != nil -%>
7+
Include <%= @include %>
8+
<% end -%>
69
<% if @accept_env != nil -%>
710
<% @accept_env.each do |v| -%>
811
AcceptEnv <%= v %>
@@ -132,9 +135,6 @@ IgnoreRhosts <%= @ignore_rhosts %>
132135
<% if @ignore_user_known_hosts != nil -%>
133136
IgnoreUserKnownHosts <%= @ignore_user_known_hosts %>
134137
<% end -%>
135-
<% if @include != nil -%>
136-
Include <%= @include %>
137-
<% end -%>
138138
<% if @ip_qos != nil -%>
139139
IPQoS <%= @ip_qos %>
140140
<% end -%>

0 commit comments

Comments
 (0)