Skip to content

Commit a842b40

Browse files
committed
feat(ansible): create a role and playbook for fail2ban
1 parent 8b2f21a commit a842b40

File tree

7 files changed

+56
-0
lines changed

7 files changed

+56
-0
lines changed

ansible/play-any--fail2ban.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
- name: Install and configure fail2ban
3+
hosts: '{{ variable_host | default("null") }}'
4+
serial: "{{ variable_serial | default(1) }}"
5+
gather_facts: false
6+
become: true
7+
become_user: root
8+
roles:
9+
- fail2ban
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
fail2ban_sshd_maxretry: 5
3+
fail2ban_sshd_findtime: 600
4+
fail2ban_sshd_bantime: 3600
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
- name: Restart fail2ban
3+
ansible.builtin.systemd:
4+
name: fail2ban
5+
state: restarted
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
- name: Deploy fail2ban jail.local
3+
ansible.builtin.template:
4+
src: jail.local.j2
5+
dest: /etc/fail2ban/jail.local
6+
owner: root
7+
group: root
8+
mode: "0644"
9+
notify: Restart fail2ban
10+
11+
- name: Enable and start fail2ban
12+
ansible.builtin.systemd:
13+
name: fail2ban
14+
enabled: true
15+
state: started
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
- name: Install fail2ban via apt
3+
ansible.builtin.apt:
4+
name: fail2ban
5+
state: present
6+
update_cache: true
7+
cache_valid_time: 3600
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
- name: Install fail2ban
3+
ansible.builtin.import_tasks: install.yml
4+
5+
- name: Configure fail2ban
6+
ansible.builtin.import_tasks: configure.yml
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[DEFAULT]
2+
banaction = iptables-multiport
3+
4+
[sshd]
5+
enabled = true
6+
port = ssh
7+
filter = sshd
8+
maxretry = {{ fail2ban_sshd_maxretry }}
9+
findtime = {{ fail2ban_sshd_findtime }}
10+
bantime = {{ fail2ban_sshd_bantime }}

0 commit comments

Comments
 (0)