2023-10-17 13:02:13 +00:00
|
|
|
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
|
# Install and configure FAIL2BAN
|
2023-10-18 07:06:20 +00:00
|
|
|
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
|
|
2023-10-18 12:24:17 +00:00
|
|
|
# comprobe if fail2ban is installed if not then install fail2ban
|
|
|
|
# Gather the package facts
|
|
|
|
- name: Gather the package facts
|
|
|
|
ansible.builtin.package_facts:
|
|
|
|
manager: auto
|
2023-10-18 12:39:33 +00:00
|
|
|
register: packages
|
2023-10-18 12:24:17 +00:00
|
|
|
|
2023-10-18 12:33:17 +00:00
|
|
|
# print the package facts in var
|
2023-10-18 12:39:33 +00:00
|
|
|
#- name: print the package facts in var
|
|
|
|
# ansible.builtin.debug:
|
|
|
|
# var: ansible_facts.packages
|
2023-10-18 12:33:17 +00:00
|
|
|
|
2023-10-18 12:24:17 +00:00
|
|
|
# install packages if is not in the system
|
|
|
|
- name: install fail2ban package if is not in the system
|
2023-10-18 07:06:20 +00:00
|
|
|
apt:
|
2023-10-18 12:24:17 +00:00
|
|
|
name: fail2ban
|
2023-10-18 07:06:20 +00:00
|
|
|
state: present
|
2023-10-18 13:25:42 +00:00
|
|
|
# when: packages.stdout.find('fail2ban') == ""
|
|
|
|
# when: "{{ packages['fail2ban'] | length }}"
|
|
|
|
when: "'fail2ban' not defined packages.stdout"
|
2023-10-18 12:24:17 +00:00
|
|
|
|
|
|
|
# config fail2ban if is there is in the system
|
|
|
|
#- name: config fail2ban
|
|
|
|
# x:
|
|
|
|
# x
|
|
|
|
# x
|
|
|
|
# when: "{{ ansible_facts.packages['fail2ban'] }} is defined "
|