Skip to content

Commit

Permalink
Merge pull request #177 from traylenator/consolidate
Browse files Browse the repository at this point in the history
Consolidate jail.conf.epp for RedHat osfamily
  • Loading branch information
bastelfreak authored Apr 5, 2022
2 parents 6bfb78c + 7677fa0 commit 7015227
Show file tree
Hide file tree
Showing 12 changed files with 66 additions and 5,717 deletions.
1 change: 1 addition & 0 deletions data/RedHat.yaml
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
---
fail2ban::config_file_before: 'paths-fedora.conf'
fail2ban::config_file_template: "fail2ban/RedHat/%{facts.os.release.major}/etc/fail2ban/jail.conf.epp"
3 changes: 3 additions & 0 deletions data/osname/CentOS-7.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
fail2ban::config_file_before: 'paths-fedora.conf'
fail2ban::config_file_template: "fail2ban/CentOS/7/etc/fail2ban/jail.conf.epp"
3 changes: 3 additions & 0 deletions hiera.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ defaults:
datadir: 'data'
data_hash: 'yaml_data'
hierarchy:
- name: 'Operating System Name and Major release'
path: 'osname/%{facts.os.name}-%{facts.os.release.major}.yaml'

- name: 'Operating System Family'
path: '%{facts.os.family}.yaml'

Expand Down
14 changes: 14 additions & 0 deletions metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,20 @@
"8",
"9"
]
},
{
"operatingsystem": "AlmaLinux",
"operatingsystemrelease": [
"8",
"9"
]
},
{
"operatingsystem": "Rocky",
"operatingsystemrelease": [
"8",
"9"
]
}
],
"requirements": [
Expand Down
24 changes: 20 additions & 4 deletions spec/acceptance/class_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,12 @@ class { 'fail2ban': }
context 'when content template' do
it 'is_expected.to work with no errors' do
pp = <<-EOS
$_config_file_template = $facts['os']['family'] ? {
'RedHat' => "fail2ban/RedHat/#{fact('os.release.major')}/#{config_file_path}.epp",
default => "fail2ban/#{fact('os.name')}/#{fact('os.release.major')}/#{config_file_path}.epp",
}
class { 'fail2ban':
config_file_template => "fail2ban/#{fact('os.name')}/#{fact('os.release.major')}/#{config_file_path}.epp",
config_file_template => $_config_file_template,
}
EOS

Expand All @@ -155,8 +159,12 @@ class { 'fail2ban':
context 'when content template and custom chain' do
it 'is_expected.to work with no errors' do
pp = <<-EOS
$_config_file_template = $facts['os']['family'] ? {
'RedHat' => "fail2ban/RedHat/#{fact('os.release.major')}/#{config_file_path}.epp",
default => "fail2ban/#{fact('os.name')}/#{fact('os.release.major')}/#{config_file_path}.epp",
}
class { 'fail2ban':
config_file_template => "fail2ban/#{fact('os.name')}/#{fact('os.release.major')}/#{config_file_path}.epp",
config_file_template => $_config_file_template,
iptables_chain => 'TEST',
}
EOS
Expand All @@ -174,8 +182,12 @@ class { 'fail2ban':
context 'when content template and custom banaction' do
it 'is_expected.to work with no errors' do
pp = <<-EOS
$_config_file_template = $facts['os']['family'] ? {
'RedHat' => "fail2ban/RedHat/#{fact('os.release.major')}/#{config_file_path}.epp",
default => "fail2ban/#{fact('os.name')}/#{fact('os.release.major')}/#{config_file_path}.epp",
}
class { 'fail2ban':
config_file_template => "fail2ban/#{fact('os.name')}/#{fact('os.release.major')}/#{config_file_path}.epp",
config_file_template => $_config_file_template,
banaction => 'iptables'
}
EOS
Expand All @@ -192,8 +204,12 @@ class { 'fail2ban':
context 'when content template and custom sender' do
it 'is_expected.to work with no errors' do
pp = <<-EOS
$_config_file_template = $facts['os']['family'] ? {
'RedHat' => "fail2ban/RedHat/#{fact('os.release.major')}/#{config_file_path}.epp",
default => "fail2ban/#{fact('os.name')}/#{fact('os.release.major')}/#{config_file_path}.epp",
}
class { 'fail2ban':
config_file_template => "fail2ban/#{fact('os.name')}/#{fact('os.release.major')}/#{config_file_path}.epp",
config_file_template => $_config_file_template,
sender => '[email protected]',
}
EOS
Expand Down
26 changes: 25 additions & 1 deletion spec/classes/init_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,38 @@
facts
end

# Hard code one existing template as a custom template
let(:config_file_template) do
"fail2ban/#{facts[:os]['name']}/#{facts[:os]['release']['major']}/etc/fail2ban/jail.conf.epp"
'fail2ban/RedHat/8/etc/fail2ban/jail.conf.epp'
end

it { is_expected.to compile.with_all_deps }
it { is_expected.to contain_class('fail2ban::install').that_comes_before('Class[fail2ban::config]') }
it { is_expected.to contain_class('fail2ban::config').that_notifies('Class[fail2ban::service]') }
it { is_expected.to contain_class('fail2ban::service') }
case [facts[:os]['name'], facts[:os]['release']['major']]
when %w[OpenSuSE 15]
it { is_expected.to contain_class('fail2ban').with_config_file_template('fail2ban/OpenSuSE/15/etc/fail2ban/jail.conf.epp') }
when %w[CentOS 7]
it { is_expected.to contain_class('fail2ban').with_config_file_template('fail2ban/CentOS/7/etc/fail2ban/jail.conf.epp') }
when %w[RedHat 7]
it { is_expected.to contain_class('fail2ban').with_config_file_template('fail2ban/RedHat/7/etc/fail2ban/jail.conf.epp') }
when %w[AlmaLinux 8], %w[RedHat 8], %w[Rocky 8], %w[CentOS 8]
it { is_expected.to contain_class('fail2ban').with_config_file_template('fail2ban/RedHat/8/etc/fail2ban/jail.conf.epp') }
when %w[AlmaLinux 9], %w[RedHat 9], %w[Rocky 9], %w[CentOS 9]
it { is_expected.to contain_class('fail2ban').with_config_file_template('fail2ban/RedHat/9/etc/fail2ban/jail.conf.epp') }
when %w[Debian 10]
it { is_expected.to contain_class('fail2ban').with_config_file_template('fail2ban/Debian/10/etc/fail2ban/jail.conf.epp') }
when %w[Debian 11]
it { is_expected.to contain_class('fail2ban').with_config_file_template('fail2ban/Debian/11/etc/fail2ban/jail.conf.epp') }
when ['Ubuntu', '18.04']
it { is_expected.to contain_class('fail2ban').with_config_file_template('fail2ban/Ubuntu/18.04/etc/fail2ban/jail.conf.epp') }
when ['Ubuntu', '20.04']
it { is_expected.to contain_class('fail2ban').with_config_file_template('fail2ban/Ubuntu/20.04/etc/fail2ban/jail.conf.epp') }
else
# has to be better way of doing this.
it { is_expected.to contain_class('fail2ban').with_config_file_template('a new os.name or os.release.major needs a new case') }
end

describe 'fail2ban::install' do
context 'defaults' do
Expand Down
Loading

0 comments on commit 7015227

Please sign in to comment.