Skip to content

Instantly share code, notes, and snippets.

@baurmatt
Created August 20, 2018 12:44
Show Gist options
  • Save baurmatt/a4b245f080353c64a75852c8da78cda5 to your computer and use it in GitHub Desktop.
Save baurmatt/a4b245f080353c64a75852c8da78cda5 to your computer and use it in GitHub Desktop.
Puppet rspec error "Could not find the daemon directory" - rspec/Puppet Code
mbaur(2018-08-20 14:43:16) ~/Sources/company-base/modules/fail2ban (pp-5655)
$ cat spec/spec_helper.rb
require 'puppetlabs_spec_helper/module_spec_helper'
require 'rspec-puppet-facts'
include RspecPuppetFacts
RSpec.configure do |config|
config.after(:suite) do
RSpec::Puppet::Coverage.report!(100)
end
end
mbaur(2018-08-20 14:43:19) ~/Sources/company-base/modules/fail2ban (pp-5655)
$ cat spec/classes/init_spec.rb
require 'spec_helper'
describe 'fail2ban', :type => :class do
on_supported_os.each do |os, facts|
let(:params) { { :enable_monitoring => false } }
let(:facts) do
facts
end
context "with default values on #{os}" do
it { should compile.with_all_deps }
## Anchors
it { should contain_anchor('fail2ban::start') }
it { should contain_anchor('fail2ban::end') }
## Classes
it { should contain_class('fail2ban::params') }
it { should contain_class('fail2ban::package') }
it { should_not contain_class('fail2ban::package::gentoo') }
it { should contain_class('fail2ban::config') }
it { should contain_class('fail2ban::service') }
## Package
it { should contain_package('fail2ban') }
## Service
it { should contain_service('fail2ban').with(
:ensure => 'running',
:enable => true,
:hasrestart => true,
:hasstatus => true,
) }
## File
it { should contain_file('/etc/fail2ban/action.d/hostsdeny.conf').with(
:ensure => 'present'
)}
it { should contain_file('/etc/fail2ban/jail.d').with(
:ensure => 'directory',
)}
it { should contain_file('/etc/fail2ban/jail.local').with(
:ensure => 'present',
)}
it { should contain_file('/etc/hosts.deny').with(
:ensure => 'present',
)}
end
end
end
mbaur(2018-08-20 14:43:21) ~/Sources/company-base/modules/fail2ban (pp-5655)
$ cat manifests/service.pp
# Class: fail2ban::service
#
# Parameters:
# none
#
class fail2ban::service (
$service = $::fail2ban::service,
$ensure = $::fail2ban::service_ensure,
$enable = $::fail2ban::service_enable,
$hasrestart = $::fail2ban::service_hasrestart,
$hasstatus = $::fail2ban::service_hasstatus,
) {
assert_private()
service { $service:
ensure => $ensure,
enable => $enable,
hasrestart => $hasrestart,
hasstatus => $hasstatus,
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment