Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 25 additions & 9 deletions manifests/filter.pp
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,30 @@
# $filterafter - indicates an filter file is read after the
# [Definition] section.
#
# $filterdefinitionvars - Variables for the INIT stanza of the filter file.
# $filterdefinitionvars - Variables for the *Definition* stanza of the filter file.
# They are tuples in the format
# "var = value"
# Can be an array like
# [ "var1 = value1", "var2 = value2",.., "varN = valueN" ]
#
# $filterinitvars - Variables for the *Init* stanza of the filter file.
# They are tuples in the format
# "var = value"
# Can be an array like
# [ "var1 = value1", "var2 = value2",.., "varN = valueN" ]
#
define fail2ban::filter (
$filtername = '',
$filtersource = '',
$filtertemplate = 'fail2ban/filter.local.erb',
$filterfailregex = '',
$filterignoreregex = '',
$filterbefore = '',
$filterafter = '',
$filtername = '',
$filtersource = '',
$filtertemplate = 'fail2ban/filter.local.erb',
$filterfailregex = '',
$filterignoreregex = '',
$filterbefore = '',
$filterafter = '',
$filterdefinitionvars = '',
$filterenable = true ) {
$filterinitvars = '',
$filterenable = true
) {

include fail2ban

Expand Down Expand Up @@ -83,6 +91,14 @@
default => $filterdefinitionvars,
}

$array_initvars = is_array($filterinitvars) ? {
false => $filterinitvars? {
'' => [],
default => [$filterinitvars],
},
default => $filterinitvars,
}

$ensure = bool2ensure($filterenable)

$manage_file_source = $filtersource ? {
Expand Down
18 changes: 15 additions & 3 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,10 @@
# Socket file used by fail2ban-client to communicate with fail2ban.
# Default: /var/run/fail2ban/fail2ban.sock
#
# [*use_epel*]
# Require the epel class before installing fail2ban packages.
# Default: false for all non-RedHat variantsd
#
# == Examples
#
# You can use this class in 2 ways:
Expand Down Expand Up @@ -344,7 +348,8 @@
$jails_source = params_lookup( 'jails_source' ),
$jails_template = params_lookup( 'jails_template' ),
$jails_template_header = params_lookup( 'jails_template_header' ),
$jails_template_footer = params_lookup( 'jails_template_footer' )
$jails_template_footer = params_lookup( 'jails_template_footer' ),
$use_epel = params_lookup( 'use_epel' ),
) inherits fail2ban::params {

$bool_source_dir_purge=any2bool($source_dir_purge)
Expand Down Expand Up @@ -420,10 +425,17 @@
default => template($fail2ban::template),
}

if $use_epel {
$pkg_require = Class['Epel']
} else {
$pkg_require = undef
}

### Managed resources
package { $fail2ban::package:
ensure => $fail2ban::manage_package,
noop => $fail2ban::noops,
ensure => $fail2ban::manage_package,
noop => $fail2ban::noops,
require => $pkg_require,
}

service { 'fail2ban':
Expand Down
2 changes: 1 addition & 1 deletion manifests/jail.pp
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@
if ! defined(Concat[$fail2ban::jails_file]) {

concat { $fail2ban::jails_file:
ensure => $ensure,
mode => $fail2ban::jails_file_mode,
warn => true,
owner => $fail2ban::jails_file_owner,
Expand All @@ -143,7 +144,6 @@
}
}
concat::fragment{ "fail2ban_jail_${name}":
ensure => $ensure,
target => $fail2ban::jails_file,
content => template('fail2ban/concat/jail.local-stanza.erb'),
order => $real_order,
Expand Down
5 changes: 5 additions & 0 deletions manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,11 @@
default => '/var/log/fail2ban/fail2ban.log',
}

$use_epel = $::operatingsystem ? {
/(?i:RedHat|Centos|Scientific|Fedora|OracleLinux)/ => true,
default => false,
}

$log_level = '3'
$socket = '/var/run/fail2ban/fail2ban.sock'

Expand Down
6 changes: 6 additions & 0 deletions templates/filter.local.erb
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,9 @@ ignoreregex = <%= @array_ignoreregex.join("\n\t") %>
<% if @array_definitionvars != [] -%>
<%= @array_definitionvars.join("\n") %>
<% end -%>

[Init]

<% if @array_initvars != [] -%>
<%= @array_initvars.join("\n") %>
<% end -%>