commit
dfc6d99c93
14 changed files with 192 additions and 27 deletions
3
.fixtures.yml
Normal file
3
.fixtures.yml
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
fixtures:
|
||||||
|
symlinks:
|
||||||
|
sshd: "#{source_dir}"
|
|
@ -7,4 +7,4 @@ summary 'ssh daemon configuration'
|
||||||
description 'Manages sshd_config'
|
description 'Manages sshd_config'
|
||||||
project_page 'https://github.com/duritong/puppet-sshd'
|
project_page 'https://github.com/duritong/puppet-sshd'
|
||||||
|
|
||||||
#dependency 'puppetlabs/stdlib', '>= 0.1.6'
|
dependency 'puppetlabs/stdlib', '>= 2.0.0'
|
|
@ -1,3 +1,3 @@
|
||||||
forge 'http://forge.puppetlabs.com'
|
forge 'http://forge.puppetlabs.com'
|
||||||
|
|
||||||
#mod 'puppetlabs/stdlib', '>=0.1.6'
|
mod 'puppetlabs/stdlib', '>=2.0.0'
|
|
@ -1,2 +1,8 @@
|
||||||
DEPENDENCIES
|
FORGE
|
||||||
|
remote: http://forge.puppetlabs.com
|
||||||
|
specs:
|
||||||
|
puppetlabs/stdlib (4.1.0)
|
||||||
|
|
||||||
|
DEPENDENCIES
|
||||||
|
puppetlabs/stdlib (>= 2.0.0)
|
||||||
|
|
||||||
|
|
|
@ -16,8 +16,7 @@ class declarations in your manifest !
|
||||||
This module requires puppet => 2.6, and the following modules are required
|
This module requires puppet => 2.6, and the following modules are required
|
||||||
pre-dependencies:
|
pre-dependencies:
|
||||||
|
|
||||||
- shared-common: `git://labs.riseup.net/shared-common`
|
- [puppetlabs/stdlib](https://github.com/puppetlabs/puppetlabs-stdlib) >= 2.x
|
||||||
- shared-lsb: `git://labs.riseup.net/shared-lsb`
|
|
||||||
|
|
||||||
## OpenSSH Server
|
## OpenSSH Server
|
||||||
|
|
||||||
|
|
8
Rakefile
8
Rakefile
|
@ -8,15 +8,9 @@ require 'rspec-system/rake_task'
|
||||||
PuppetLint.configuration.log_format = '%{path}:%{linenumber}:%{KIND}: %{message}'
|
PuppetLint.configuration.log_format = '%{path}:%{linenumber}:%{KIND}: %{message}'
|
||||||
PuppetLint.configuration.send("disable_80chars")
|
PuppetLint.configuration.send("disable_80chars")
|
||||||
|
|
||||||
# use librarian-puppet to manage fixtures instead of .fixtures.yml
|
|
||||||
# offers more possibilities like explicit version management, forge downloads,...
|
|
||||||
puppet_module='sshd'
|
puppet_module='sshd'
|
||||||
task :librarian_spec_prep do
|
task :librarian_spec_prep do
|
||||||
sh "librarian-puppet install --path=spec/fixtures/modules/"
|
sh 'librarian-puppet install --path=spec/fixtures/modules/'
|
||||||
pwd = `pwd`.strip
|
|
||||||
unless File.directory?("#{pwd}/spec/fixtures/modules/#{puppet_module}")
|
|
||||||
sh "ln -s #{pwd} #{pwd}/spec/fixtures/modules/#{puppet_module}"
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
task :spec_prep => :librarian_spec_prep
|
task :spec_prep => :librarian_spec_prep
|
||||||
task :default => [:spec, :lint]
|
task :default => [:spec, :lint]
|
|
@ -6,6 +6,7 @@ class sshd::base {
|
||||||
}
|
}
|
||||||
|
|
||||||
file { 'sshd_config':
|
file { 'sshd_config':
|
||||||
|
ensure => present,
|
||||||
path => '/etc/ssh/sshd_config',
|
path => '/etc/ssh/sshd_config',
|
||||||
content => $sshd_config_content,
|
content => $sshd_config_content,
|
||||||
notify => Service[sshd],
|
notify => Service[sshd],
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
class sshd::client::base {
|
class sshd::client::base {
|
||||||
# this is needed because the gid might have changed
|
# this is needed because the gid might have changed
|
||||||
file { '/etc/ssh/ssh_known_hosts':
|
file { '/etc/ssh/ssh_known_hosts':
|
||||||
mode => '0644',
|
ensure => present,
|
||||||
owner => root,
|
mode => '0644',
|
||||||
group => 0;
|
owner => root,
|
||||||
|
group => 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
# Now collect all server keys
|
# Now collect all server keys
|
||||||
|
|
|
@ -1,21 +1,13 @@
|
||||||
class sshd::debian inherits sshd::linux {
|
class sshd::debian inherits sshd::linux {
|
||||||
|
|
||||||
# the templates for Debian need lsbdistcodename
|
|
||||||
require lsb
|
|
||||||
|
|
||||||
Package[openssh]{
|
Package[openssh]{
|
||||||
name => 'openssh-server',
|
name => 'openssh-server',
|
||||||
}
|
}
|
||||||
|
|
||||||
$sshd_restartandstatus = $::lsbdistcodename ? {
|
|
||||||
etch => false,
|
|
||||||
default => true
|
|
||||||
}
|
|
||||||
|
|
||||||
Service[sshd]{
|
Service[sshd]{
|
||||||
name => 'ssh',
|
name => 'ssh',
|
||||||
pattern => 'sshd',
|
pattern => 'sshd',
|
||||||
hasstatus => $sshd_restartandstatus,
|
hasstatus => true,
|
||||||
hasrestart => $sshd_restartandstatus,
|
hasrestart => true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,6 +36,10 @@ class sshd(
|
||||||
$shorewall_source = 'net'
|
$shorewall_source = 'net'
|
||||||
) {
|
) {
|
||||||
|
|
||||||
|
validate_bool($manage_shorewall)
|
||||||
|
validate_array($listen_address)
|
||||||
|
validate_array($ports)
|
||||||
|
|
||||||
class{'sshd::client':
|
class{'sshd::client':
|
||||||
shared_ip => $sshd::shared_ip,
|
shared_ip => $sshd::shared_ip,
|
||||||
ensure_version => $sshd::ensure_version,
|
ensure_version => $sshd::ensure_version,
|
||||||
|
|
42
spec/classes/client_spec.rb
Normal file
42
spec/classes/client_spec.rb
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
require 'spec_helper'
|
||||||
|
|
||||||
|
describe 'sshd::client' do
|
||||||
|
|
||||||
|
shared_examples "a Linux OS" do
|
||||||
|
it { should contain_file('/etc/ssh/ssh_known_hosts').with(
|
||||||
|
{
|
||||||
|
'ensure' => 'present',
|
||||||
|
'owner' => 'root',
|
||||||
|
'group' => '0',
|
||||||
|
'mode' => '0644',
|
||||||
|
}
|
||||||
|
)}
|
||||||
|
end
|
||||||
|
|
||||||
|
context "Debian OS" do
|
||||||
|
let :facts do
|
||||||
|
{
|
||||||
|
:operatingsystem => 'Debian',
|
||||||
|
:osfamily => 'Debian',
|
||||||
|
:lsbdistcodename => 'wheezy',
|
||||||
|
}
|
||||||
|
end
|
||||||
|
it_behaves_like "a Linux OS"
|
||||||
|
it { should contain_package('openssh-clients').with({
|
||||||
|
'name' => 'openssh-client'
|
||||||
|
}) }
|
||||||
|
end
|
||||||
|
|
||||||
|
context "CentOS" do
|
||||||
|
it_behaves_like "a Linux OS" do
|
||||||
|
let :facts do
|
||||||
|
{
|
||||||
|
:operatingsystem => 'CentOS',
|
||||||
|
:osfamily => 'RedHat',
|
||||||
|
:lsbdistcodename => 'Final',
|
||||||
|
}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
122
spec/classes/init_spec.rb
Normal file
122
spec/classes/init_spec.rb
Normal file
|
@ -0,0 +1,122 @@
|
||||||
|
require 'spec_helper'
|
||||||
|
|
||||||
|
describe 'sshd' do
|
||||||
|
|
||||||
|
shared_examples "a Linux OS" do
|
||||||
|
it { should compile.with_all_deps }
|
||||||
|
it { should contain_class('sshd') }
|
||||||
|
it { should contain_class('sshd::client') }
|
||||||
|
|
||||||
|
it { should contain_service('sshd').with({
|
||||||
|
:ensure => 'running',
|
||||||
|
:enable => true,
|
||||||
|
:hasstatus => true
|
||||||
|
})}
|
||||||
|
|
||||||
|
it { should contain_file('sshd_config').with(
|
||||||
|
{
|
||||||
|
'ensure' => 'present',
|
||||||
|
'owner' => 'root',
|
||||||
|
'group' => '0',
|
||||||
|
'mode' => '0600',
|
||||||
|
}
|
||||||
|
)}
|
||||||
|
|
||||||
|
context 'change ssh port' do
|
||||||
|
let(:params){{
|
||||||
|
:ports => [ 22222],
|
||||||
|
}}
|
||||||
|
it { should contain_file(
|
||||||
|
'sshd_config'
|
||||||
|
).with_content(/Port 22222/)}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "Debian OS" do
|
||||||
|
let :facts do
|
||||||
|
{
|
||||||
|
:operatingsystem => 'Debian',
|
||||||
|
:osfamily => 'Debian',
|
||||||
|
:lsbdistcodename => 'wheezy',
|
||||||
|
}
|
||||||
|
end
|
||||||
|
it_behaves_like "a Linux OS"
|
||||||
|
it { should contain_package('openssh') }
|
||||||
|
it { should contain_class('sshd::debian') }
|
||||||
|
it { should contain_service('sshd').with(
|
||||||
|
:hasrestart => true
|
||||||
|
)}
|
||||||
|
|
||||||
|
context "Ubuntu" do
|
||||||
|
let :facts do
|
||||||
|
{
|
||||||
|
:operatingsystem => 'Ubuntu',
|
||||||
|
:lsbdistcodename => 'precise',
|
||||||
|
}
|
||||||
|
end
|
||||||
|
it_behaves_like "a Linux OS"
|
||||||
|
it { should contain_package('openssh') }
|
||||||
|
it { should contain_service('sshd').with({
|
||||||
|
:hasrestart => true
|
||||||
|
})}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
# context "RedHat OS" do
|
||||||
|
# it_behaves_like "a Linux OS" do
|
||||||
|
# let :facts do
|
||||||
|
# {
|
||||||
|
# :operatingsystem => 'RedHat',
|
||||||
|
# :osfamily => 'RedHat',
|
||||||
|
# }
|
||||||
|
# end
|
||||||
|
# end
|
||||||
|
# end
|
||||||
|
|
||||||
|
context "CentOS" do
|
||||||
|
it_behaves_like "a Linux OS" do
|
||||||
|
let :facts do
|
||||||
|
{
|
||||||
|
:operatingsystem => 'CentOS',
|
||||||
|
:osfamily => 'RedHat',
|
||||||
|
:lsbdistcodename => 'Final',
|
||||||
|
}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "Gentoo" do
|
||||||
|
let :facts do
|
||||||
|
{
|
||||||
|
:operatingsystem => 'Gentoo',
|
||||||
|
:osfamily => 'Gentoo',
|
||||||
|
}
|
||||||
|
end
|
||||||
|
it_behaves_like "a Linux OS"
|
||||||
|
it { should contain_class('sshd::gentoo') }
|
||||||
|
end
|
||||||
|
|
||||||
|
context "OpenBSD" do
|
||||||
|
let :facts do
|
||||||
|
{
|
||||||
|
:operatingsystem => 'OpenBSD',
|
||||||
|
:osfamily => 'OpenBSD',
|
||||||
|
}
|
||||||
|
end
|
||||||
|
it_behaves_like "a Linux OS"
|
||||||
|
it { should contain_class('sshd::openbsd') }
|
||||||
|
end
|
||||||
|
|
||||||
|
# context "FreeBSD" do
|
||||||
|
# it_behaves_like "a Linux OS" do
|
||||||
|
# let :facts do
|
||||||
|
# {
|
||||||
|
# :operatingsystem => 'FreeBSD',
|
||||||
|
# :osfamily => 'FreeBSD',
|
||||||
|
# }
|
||||||
|
# end
|
||||||
|
# end
|
||||||
|
# end
|
||||||
|
|
||||||
|
end
|
|
@ -3,7 +3,7 @@ $LOAD_PATH.unshift File.join(dir, 'lib')
|
||||||
require 'puppet'
|
require 'puppet'
|
||||||
require 'rspec'
|
require 'rspec'
|
||||||
require 'puppetlabs_spec_helper/module_spec_helper'
|
require 'puppetlabs_spec_helper/module_spec_helper'
|
||||||
require 'rspec-hiera-puppet'
|
#require 'rspec-hiera-puppet'
|
||||||
require 'rspec-puppet/coverage'
|
require 'rspec-puppet/coverage'
|
||||||
require 'rspec/autorun'
|
require 'rspec/autorun'
|
||||||
|
|
||||||
|
|
|
@ -20,5 +20,6 @@ RSpec.configure do |c|
|
||||||
puppet_install
|
puppet_install
|
||||||
# Install modules and dependencies
|
# Install modules and dependencies
|
||||||
puppet_module_install(:source => proj_root, :module_name => 'sshd')
|
puppet_module_install(:source => proj_root, :module_name => 'sshd')
|
||||||
|
shell('puppet module install puppetlabs-stdlib')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue