Showing with 66 additions and 8 deletions.
  1. +5 −0 README.md
  2. +17 −7 manifests/init.pp
  3. +1 −1 metadata.json
  4. +43 −0 spec/classes/init_spec.rb
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -606,6 +606,11 @@ Content of root's ~/.ssh/config.

- *Default*: "# This file is being maintained by Puppet.\n# DO NOT EDIT\n"

manage_service
--------------
Manage the sshd service through this module or not. Valid values are 'true' and 'false'.

- *Default*: 'true'

===
# Manage user's ssh_authorized_keys
Expand Down
24 changes: 17 additions & 7 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
$sshd_hostbasedauthentication = 'no',
$sshd_ignoreuserknownhosts = 'no',
$sshd_ignorerhosts = 'yes',
$manage_service = true,
$service_ensure = 'running',
$service_name = 'USE_DEFAULTS',
$service_enable = true,
Expand Down Expand Up @@ -580,6 +581,13 @@
}
validate_bool($purge_keys_real)

if type3x($manage_service) == 'string' {
$manage_service_real = str2bool($manage_service)
} else {
$manage_service_real = $manage_service
}
validate_bool($manage_service_real)

if type3x($service_enable) == 'string' {
$service_enable_real = str2bool($service_enable)
} else {
Expand Down Expand Up @@ -703,13 +711,15 @@
}
}

service { 'sshd_service' :
ensure => $service_ensure,
name => $service_name_real,
enable => $service_enable_real,
hasrestart => $service_hasrestart_real,
hasstatus => $service_hasstatus_real,
subscribe => File['sshd_config'],
if $manage_service_real {
service { 'sshd_service' :
ensure => $service_ensure,
name => $service_name_real,
enable => $service_enable_real,
hasrestart => $service_hasrestart_real,
hasstatus => $service_hasstatus_real,
subscribe => File['sshd_config'],
}
}

if $manage_firewall == true {
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": "ghoneycutt-ssh",
"version": "3.31.0",
"version": "3.32.0",
"author": "ghoneycutt",
"summary": "Manages SSH",
"license": "Apache-2.0",
Expand Down
43 changes: 43 additions & 0 deletions spec/classes/init_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3371,4 +3371,47 @@
end
end
end

describe 'with parameter manage_service' do
let(:facts) do
{ :fqdn => 'monkey.example.com',
:osfamily => 'RedHat',
:sshrsakey => 'AAAAB3NzaC1yc2EAAAABIwAAAQEArGElx46pD6NNnlxVaTbp0ZJMgBKCmbTCT3RaeCk0ZUJtQ8wkcwTtqIXmmiuFsynUT0DFSd8UIodnBOPqitimmooAVAiAi30TtJVzADfPScMiUnBJKZajIBkEMkwUcqsfh630jyBvLPE/kyQcxbEeGtbu1DG3monkeymanOBW1AKc5o+cJLXcInLnbowMG7NXzujT3BRYn/9s5vtT1V9cuZJs4XLRXQ50NluxJI7sVfRPVvQI9EMbTS4AFBXUej3yfgaLSV+nPZC/lmJ2gR4t/tKvMFF9m16f8IcZKK7o0rK7v81G/tREbOT5YhcKLK+0wBfR6RsmHzwy4EddZloyLQ=='
}
end

['YES','badvalue',2.42,['array'],a = { 'ha' => 'sh' }].each do |value|
context "specified as invalid value #{value} (as #{value.class})" do
let(:params) { { :manage_service => value } }
it do
expect {
should contain_class('ssh')
}.to raise_error(Puppet::Error,/(is not a boolean|Unknown type of boolean)/)
end
end
end

['true', true].each do |value|
context "specified as valid true value #{value} (as #{value.class})" do
let(:params) { { :manage_service => value } }
it do
expect {
should contain_service('sshd_service')
}
end
end
end

['false', false].each do |value|
context "specified as valid false value #{value} (as #{value.class})" do
let(:params) { { :manage_service => value } }
it do
expect {
should_not contain_service('sshd_service')
}
end
end
end
end

end