vn-ansible/roles/config-fail2ban/tasks/main.yaml

50 lines
1.9 KiB
YAML
Raw Normal View History

2023-12-19 13:13:53 +00:00
# ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2023-10-17 13:02:13 +00:00
# Install and configure FAIL2BAN
2023-12-19 13:13:53 +00:00
# ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2023-10-18 07:06:20 +00:00
2024-02-15 16:18:29 +00:00
- name: "[CONFIG FAIL2BAN] Comprobando si es necesario configurar fail2ban"
2024-02-15 16:17:50 +00:00
meta: end_host
when: fail2ban_enabled is not defined or not fail2ban_enabled
2023-12-19 13:13:53 +00:00
# ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2023-10-18 12:24:17 +00:00
# comprobe if fail2ban is installed if not then install fail2ban
# Gather the package facts
2023-12-19 13:13:53 +00:00
# - name: Gather the package facts
2023-10-26 12:16:21 +00:00
# package_facts:
# manager: auto
2023-12-19 13:13:53 +00:00
# ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2023-10-18 12:24:17 +00:00
# install packages if is not in the system
2023-10-26 12:18:17 +00:00
- name: install fail2ban package if is not in the system
apt:
name: fail2ban
state: present
# when: "'fail2ban' not in ansible_facts.packages" # ansible comprobes if is ok its installed
2023-12-19 13:13:53 +00:00
# ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2023-10-18 12:24:17 +00:00
2023-12-19 13:13:53 +00:00
# ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2023-10-19 09:21:54 +00:00
# configure fail2ban
# template a file to /etc/fail2ban/jail.local
- name: template a file to /etc/fail2ban/jail.local
template:
2023-10-27 08:02:22 +00:00
src: jail2.j2
2023-10-19 09:21:54 +00:00
dest: "{{ path_jail_local }}"
owner: root
group: root
mode: '0644'
backup: true
2023-10-26 12:16:21 +00:00
notify: restart fail2ban
2023-12-19 13:13:53 +00:00
# ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2024-02-12 16:24:01 +00:00
# service fail2ban should start on boot.
- name: service should start on boot
service:
name: "{{ fail2ban_daemon }}"
enabled: yes
2023-10-26 12:16:21 +00:00
# service nftables should start on boot.
- name: service nftables should start on boot
2023-10-23 15:15:57 +00:00
service:
2023-10-26 12:16:21 +00:00
name: "{{ nftables_daemon }}"
2023-12-19 13:13:53 +00:00
enabled: true
2023-10-26 12:16:21 +00:00
notify: restart nftables
2023-12-19 13:13:53 +00:00
# ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++