Skip to content

Commit 2fc6704

Browse files
committed
Added support for fail2ban
1 parent 240453b commit 2fc6704

File tree

5 files changed

+63
-2
lines changed

5 files changed

+63
-2
lines changed

.rkd/makefile.yaml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,3 +94,20 @@ tasks:
9494
export EDITOR=${TEXT_EDITOR};
9595
ansible-vault edit "${inventory_path}"
9696
cd inventory && git add host_vars/${ARG_HOST}.yaml
97+
98+
:node:edit:all-hosts-defaults-config:
99+
description: Edit a file that contains common values for all hosts
100+
steps: |
101+
inventory_path=./inventory/group_vars/all.yaml
102+
export EDITOR=${TEXT_EDITOR};
103+
104+
if [[ ! -f "${inventory_path}" ]]; then
105+
%RKD% :node:copy-host-defaults
106+
fi
107+
108+
if [[ "$(cat $inventory_path)" == *"ANSIBLE_VAULT"* ]]; then
109+
ansible-vault edit "${inventory_path}"
110+
exit 0
111+
fi
112+
113+
${EDITOR} "${inventory_path}"

.templates/inventory/group_vars/all.yaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,21 @@ default_role_logs:
144144
systemd_max_file_sec: 1month
145145

146146

147+
# https://github.com/Oefenweb/ansible-fail2ban
148+
default_role_fail2ban:
149+
fail2ban_dbpurgeage: 86400
150+
fail2ban_loglevel: "INFO"
151+
fail2ban_logtarget: "SYSLOG"
152+
fail2ban_syslog_target: "/var/log/fail2ban.log"
153+
fail2ban_ignoreips: [127.0.0.1/8]
154+
fail2ban_bantime: 600
155+
fail2ban_maxretry: 6
156+
fail2ban_services:
157+
- name: sshd
158+
port: "{{ ansible_ssh_port }}"
159+
maxretry: 6
160+
bantime: 600
161+
147162
default_role_system_settings:
148163
timezone: Europe/Rome
149164
locale: "en_GB.UTF-8"

README.md

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,15 +107,32 @@ With this combination you can divide access to multiple admins handling administ
107107
nano .env
108108
```
109109

110-
Editing inventory per host
111-
--------------------------
110+
Editing configuration per host and disabling/enabling roles
111+
-----------------------------------------------------------
112112

113113
This command will automatically encrypt existing and new file using AES-256 with Ansible Vault.
114114

115+
**Please note: All values there are overriding `group_vars/all.yaml` default values for edited host**
116+
117+
**To disable a role - remove or comment out it's section eg. `role_fail2ban`**
118+
119+
**To enable a role without overriding any values (inheriting all defaults) just add empty section eg. `role_fail2ban: {}`**
120+
115121
```bash
116122
rkd :edit:host-config my-host.org
117123
```
118124

125+
Setting default values for ALL hosts in inventory (hosts will inherit those values by default)
126+
----------------------------------------------------------------------------------------------
127+
128+
When a host does not override given value, then it is inherited from global defaults.
129+
130+
*Note: This file you can also encrypt and below command will support encrypted edits*
131+
132+
```bash
133+
rkd :edit:all-hosts-defaults-config
134+
```
135+
119136
Deploying
120137
---------
121138

playbooks/prepare-machine.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,3 +88,13 @@
8888

8989
- include_role: name=infrastructure-ansible-logs
9090
tags: logs
91+
92+
- name: Fail2ban role
93+
when: role_fail2ban is defined
94+
block:
95+
- name: Include required vars
96+
set_fact:
97+
args: "{{ default_role_fail2ban | combine(role_fail2ban | default({}), recursive=True) }}"
98+
99+
- include_role: name=oefenweb.fail2ban
100+
tags: fail2ban

requirements.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,5 @@ roles:
66
- src: blackandred.server_basic_security
77
- src: git+https://github.com/riotkit-org/infrastructure-ansible-tweak-os
88
- src: blackandred.server_secure_storage
9+
- src: oefenweb.fail2ban
10+
version: v3.3.14

0 commit comments

Comments
 (0)