Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,5 @@ security_autoupdate_mail_to: ""
security_autoupdate_mail_on_error: true

security_fail2ban_enabled: true
security_fail2ban_custom_configuration_template: "jail.local.j2"
security_fail2ban_custom_jail_template: "jail.local.j2"
security_fail2ban_custom_configuration_template: "fail2ban.local.j2"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically, the variable name security_fail2ban_custom_configuration_template seems to be good for fail2ban.local. Nevertheless, for backward compatibility it would be better to keep it for the jail.local and create a new variable for the fail2ban.local config.

Proposal:

security_fail2ban_custom_fail2ban_local_template: "fail2ban.local.j2"
security_fail2ban_custom_configuration_template: "jail.local.j2"

In this case only the line

src: fail2ban.local.j2

needs to be changed to

src: "{{ security_fail2ban_custom_fail2ban_local_template }}"

in file tasks/fail2ban.yml

Copy link

@PascalKont PascalKont Dec 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this creates unnecessary confusion, or rather continues the existing confusion in the variable names.
How about creating two new variables, without the custom in the name and removing the old vars content:

Suggested change
security_fail2ban_custom_configuration_template: "fail2ban.local.j2"
security_fail2ban_jail_template: "jail.local.j2"
security_fail2ban_configuration_template: "fail2ban.local.j2"
# Deprecated variable, please dont't use it anymore:
# security_fail2ban_custom_configuration_template: "jail.local.j2"

Finally, adding a deprecation warning task. Which at some point could be changed to be a fail:

- name: Assert for deprecated variable
  assert:
    quiet: true
    that:
      - security_fail2ban_custom_configuration_template is not defined
    fail_msg: |
      [DEPRECATION WARNING]: security_fail2ban_custom_configuration_template is deprecated
      Origin: {{ role_path }}

      Use `security_fail2ban_jail_template` instead.
  ignore_errors: true
  register: deprecated_variable

- name: Set value of deprecated_variable into correct variable
  set_fact:
    security_fail2ban_jail_template: "{{ security_fail2ban_custom_configuration_template }}"
  when:
    - deprecated_variable.failed is true

I have implemented this in my branch here

3 changes: 2 additions & 1 deletion tasks/fail2ban.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

- name: Copy jail custom configuration file into place.
template:
src: "{{ security_fail2ban_custom_configuration_template }}"
src: "{{ security_fail2ban_custom_jail_template }}"
dest: /etc/fail2ban/jail.local
owner: root
group: root
Expand All @@ -25,6 +25,7 @@
- name: Copy fail2ban custom configuration file into place.
template:
src: fail2ban.local.j2

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line src: fail2ban.local.j2 needs to removed. Then it should work.

src: "{{ security_fail2ban_custom_configuration_template }}"
dest: /etc/fail2ban/fail2ban.local
owner: root
group: root
Expand Down
Loading