Skip to content

Commit

Permalink
Moving to collections instead of modules shipped with Ansible.
Browse files Browse the repository at this point in the history
  • Loading branch information
robert-de-bock committed Feb 19, 2021
1 parent b5ed303 commit 7a4acdb
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 19 deletions.
2 changes: 1 addition & 1 deletion handlers/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# handlers file for fail2ban

- name: restart fail2ban
service:
ansible.builtin.service:
name: "{{ fail2ban_service }}"
state: restarted
when:
Expand Down
3 changes: 3 additions & 0 deletions requirements.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@
roles:
- name: robertdebock.bootstrap
- name: robertdebock.epel
collections:
- name: ansible.builtin
- name: community.general
24 changes: 12 additions & 12 deletions tasks/assert.yml
Original file line number Diff line number Diff line change
@@ -1,83 +1,83 @@
---

- name: test if fail2ban_loglevel is set correctly
assert:
ansible.builtin.assert:
that:
- fail2ban_loglevel is defined
- fail2ban_loglevel is string
- fail2ban_loglevel in [ "CRITICAL", "ERROR", "WARNING", "NOTICE", "INFO", "DEBUG" ]
quiet: yes

- name: test if fail2ban_logtarget is set correctly
assert:
ansible.builtin.assert:
that:
- fail2ban_logtarget is defined
- fail2ban_logtarget is string
quiet: yes

- name: test if fail2ban_ignoreself is set correctly
assert:
ansible.builtin.assert:
that:
- fail2ban_ignoreself is defined
- fail2ban_ignoreself is string
- fail2ban_ignoreself in [ "false", "true" ]
quiet: yes

- name: test if fail2ban_ignoreips is set correctly
assert:
ansible.builtin.assert:
that:
- fail2ban_ignoreips is defined
- fail2ban_ignoreips is string
quiet: yes

- name: test if fail2ban_bantime is set correctly
assert:
ansible.builtin.assert:
that:
- fail2ban_bantime is defined
- fail2ban_bantime is number
- fail2ban_bantime >= -1 and fail2ban_bantime !=0
quiet: yes

- name: test if fail2ban_findtime is set correctly
assert:
ansible.builtin.assert:
that:
- fail2ban_findtime is defined
- fail2ban_findtime is number
- fail2ban_findtime > 0
quiet: yes

- name: test if fail2ban_maxretry is set correctly
assert:
ansible.builtin.assert:
that:
- fail2ban_maxretry is defined
- fail2ban_maxretry is number
- fail2ban_maxretry > 0
quiet: yes

- name: test if fail2ban_destemail is set correctly
assert:
ansible.builtin.assert:
that:
- fail2ban_destemail is defined
- fail2ban_destemail is string
quiet: yes

- name: test if fail2ban_sender is set correctly
assert:
ansible.builtin.assert:
that:
- fail2ban_sender is defined
- fail2ban_sender is string
quiet: yes

- name: test if fail2ban_configuration is set correctly
assert:
ansible.builtin.assert:
that:
- fail2ban_configuration is iterable
quiet: yes
when:
- fail2ban_configuration is defined

- name: test if item in fail2ban_configuration is set correctly
assert:
ansible.builtin.assert:
that:
- item.option is defined
- item.option is string
Expand All @@ -93,7 +93,7 @@
- fail2ban_configuration is iterable

- name: test if fail2ban_jail_configuration is set correctly
assert:
ansible.builtin.assert:
that:
- item.option is defined
- item.option is string
Expand Down
12 changes: 6 additions & 6 deletions tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
delegate_to: localhost

- name: install fail2ban
package:
ansible.builtin.package:
name: "{{ fail2ban_packages }}"
state: present

- name: configure fail2ban.conf
ini_file:
community.general.ini_file:
path: /etc/fail2ban/fail2ban.conf
section: "{{ item.section }}"
option: "{{ item.option }}"
Expand All @@ -25,7 +25,7 @@
label: "{{ item.option }}"

- name: configure jail.local
ini_file:
community.general.ini_file:
path: /etc/fail2ban/jail.local
section: "{{ item.section }}"
option: "{{ item.option }}"
Expand All @@ -38,12 +38,12 @@
label: "{{ item.option }}"

- name: stat auth log file
stat:
ansible.builtin.stat:
path: /var/log/auth.log
register: fail2ban_auth

- name: touch auth log file
file:
ansible.builtin.file:
path: /var/log/auth.log
state: touch
mode: "0640"
Expand All @@ -52,7 +52,7 @@
- not fail2ban_auth.stat.exists

- name: start and enable fail2ban
service:
ansible.builtin.service:
name: "{{ fail2ban_service }}"
state: started
enabled: yes

0 comments on commit 7a4acdb

Please sign in to comment.