Ansible Role: fail2ban
An ansible role to install and configure fail2ban.
Requirements
This role has been tested on
Ubuntu 16.04
andUbuntu 16.10
only.
Variables
-
fail2ban_loglevel
: which log level should it be output as.- Default:
3
- Options:
1
= ERROR2
= WARN3
= INFO4
= DEBUG
- Default:
-
fail2ban_logtarget
: where should log outputs be sent.- Default:
/var/log/fail2ban.log
- Options:
SYSLOG
STDERR
STDOUT
filepath
- Default:
-
fail2ban_socket
: here should the socket be created.- Default:
/var/run/fail2ban/fail2ban.sock
- Default:
-
fail2ban_ignoreip
: which IP address, CIDR mark or DNS host should be ignored.- Default:
127.0.0.1/8
- Default:
-
fail2ban_bantime
: how long (seconds) should the ban last for- Default:
600
- Default:
-
fail2ban_maxretry
: default number of failed attempts before being banned.- Default:
4
- Default:
-
fail2ban_backend
: how should the file changes be detected- Default:
polling
- Options:
gamin
polling
auto
- Default:
-
fail2ban_destemail
: where should e-mail reports be sent- Default:
root
- Default:
-
fail2ban_banaction
: default method of how the ban should be applied- Default:
iptables-multiport
- Options:
iptables
iptables-new
iptables-multiport
shorewall
- Default:
-
fail2ban_mta
: what e-mail action should be used- Default:
sendmail
- Options:
sendmail
mail
- Default:
-
fail2ban_protocol
: what should the default protocol be- Default:
tcp
- Default:
-
`fail2ban_chain: which chain would the JUMPs be added into iptables-*
- Default:
INPUT
- Default:
-
fail2ban_action
: default action fail2ban takes when it wants to institute a ban- Default:
action_mw
- Options:
action_
: configure iptables to reject trafficaction_mw
: send an email in addition to rejectionaction_mwl
: include relevant log lines in the email
- Default:
-
fail2ban_services
: list of services fail2ban should monitor- Default:
- name: ssh port: ssh filter: sshd logpath: /var/log/auth.log
- Default:
Service Definition
Each service in the list should conform to the following definition.
-
name
: the name of the service.- Required
-
enabled
: enable monitoring this service. must be a string.- Default:
true
- Default:
-
port
: port used by the service. Separate multiple ports with comma. No spaces.- Required
-
protocol
: protocol used by the service.- Default:
tcp
- Default:
-
filter
: filter that will be used to decide whether a line in a log indicates a failed authentication.- Required
-
logpath
: where the logs for the service are located.- Required
-
maxretry
: number of faliled attempts before being banned.- Default: the value defined in
fail2ban_maxretry
- Default: the value defined in
-
action
: action fail2ban takes when it wants to institute a ban- Default: the value defined in
fail2ban_action
- Options:
action_
: configure iptables to reject trafficaction_mw
: send an email in addition to rejectionaction_mwl
: include relevant log lines in the email
- Default: the value defined in
-
banaction
: method of how the ban should be applied- Default: the value defined in
fail2ban_banaction
- Options:
iptables
iptables-new
iptables-multiport
shorewall
- Default: the value defined in
Usage Example
- hosts: all
vars:
fail2ban_services:
- name: ssh
port: ssh
filter: sshd
logpath: /var/log/auth.log
- name: postfix
port: smtp,ssmtp
filter: postfix
logpath: /var/log/mail.log
roles:
- thedumbtechguy.fail2ban
License
MIT / BSD
Author Information
This role was created by TheDumbTechGuy ( twitter | blog | galaxy )
Credits
This role was built upon the original work of: