Skip to content

Commit

Permalink
Move custom configurations management to dedicated tasks list
Browse files Browse the repository at this point in the history
This allows to use the `tasks_from` parameter of the `import_role` module.
For instance, one could run something like :
```
- name: "Create Traefik fail2ban configuration."
  import_role:
    name: ansible-fail2ban
    tasks_from: copy_custom_configurations
  become: True
  vars:
    fail2ban_filterd_path: "{{ traefik_fail2ban_filterd_path }}"
    fail2ban_actiond_path: "{{ traefik_fail2ban_actiond_path }}"
    fail2ban_jaild_path: "{{ traefik_fail2ban_jaild_path }}"
```
from a Traefik playbook to just add Traefik specific Fail2ban configuration
without reconfiguring everything.
  • Loading branch information
Jonathan Piron authored and jpiron committed Jan 19, 2021
1 parent eebcd2a commit 401b44b
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 41 deletions.
12 changes: 12 additions & 0 deletions tasks/copy_actions.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
- name: copy actions
copy:
src: "{{ fail2ban_actiond_path }}"
dest: /etc/fail2ban/action.d/
owner: root
group: root
mode: 0644
notify: restart fail2ban
tags:
- configuration
- fail2ban
- fail2ban-actions
11 changes: 11 additions & 0 deletions tasks/copy_custom_configurations.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
- name: copy filters
import_tasks: copy_filters.yml
when: fail2ban_filterd_path is defined

- name: copy actions
import_tasks: copy_actions.yml
when: fail2ban_actiond_path is defined

- name: copy jails
import_tasks: copy_jails.yml
when: fail2ban_jaild_path is defined
12 changes: 12 additions & 0 deletions tasks/copy_filters.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
- name: copy filters
copy:
src: "{{ fail2ban_filterd_path }}"
dest: /etc/fail2ban/filter.d/
owner: root
group: root
mode: 0644
notify: restart fail2ban
tags:
- configuration
- fail2ban
- fail2ban-filters
12 changes: 12 additions & 0 deletions tasks/copy_jails.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
- name: copy jails
copy:
src: "{{ fail2ban_jaild_path }}"
dest: /etc/fail2ban/jail.d/
owner: root
group: root
mode: 0644
notify: restart fail2ban
tags:
- configuration
- fail2ban
- fail2ban-jails
43 changes: 2 additions & 41 deletions tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,47 +50,8 @@
- fail2ban-configuration
- fail2ban-configuration-update

- name: copy filters
copy:
src: "{{ fail2ban_filterd_path }}"
dest: /etc/fail2ban/filter.d/
owner: root
group: root
mode: 0644
when: fail2ban_filterd_path is defined
notify: restart fail2ban
tags:
- configuration
- fail2ban
- fail2ban-filters

- name: copy actions
copy:
src: "{{ fail2ban_actiond_path }}"
dest: /etc/fail2ban/action.d/
owner: root
group: root
mode: 0644
when: fail2ban_actiond_path is defined
notify: restart fail2ban
tags:
- configuration
- fail2ban
- fail2ban-actions

- name: copy jails
copy:
src: "{{ fail2ban_jaild_path }}"
dest: /etc/fail2ban/jail.d/
owner: root
group: root
mode: 0644
when: fail2ban_jaild_path is defined
notify: restart fail2ban
tags:
- configuration
- fail2ban
- fail2ban-jails
- name: copy custom configurations
import_tasks: copy_custom_configurations.yml

- name: start and enable service
service:
Expand Down

0 comments on commit 401b44b

Please sign in to comment.