fail2ban_ignoreip: a list of addresses or networks written as ignoreip in a new [DEFAULT] section of jail.local. The default is Fail2Ban's own (127.0.0.1/8, ::1), so nothing changes unless a consumer sets it.
Why
The role had no way to keep a trusted address from being banned. A mistyped key or a looping health check from the machine that runs Ansible, or from a CI runner, can get that address banned and lock automation out of the host. [DEFAULT] covers both the jails of fail2ban_jails and the service jails that other roles add with tasks_from: service_jail (written to jail.d); a per-jail ignoreip would need repeating on every jail and would miss service jails.
Changes
defaults/main.yml, templates/jail.local.j2: the variable and the [DEFAULT] block.
tasks/validate.yml: the value must be a list of non-empty strings (argument_specs accepts a plain string for a list option and leaves it a string, and accepts numbers and null in the list, so the type is checked here first). Entries must hold no whitespace (they are joined with spaces), no ; (after whitespace it starts an inline comment in Fail2Ban's config files, which drops the rest of the line without an error) and no % (interpolation syntax, which fails the whole config after jail.local is written). The pattern ends in \Z, not $.
meta/argument_specs.yml (typed option; the role description mentions the validation), README, changelog fragment (minor_changes).
Documented limits: service_jail does not read the variable; the value replaces an ignoreip set in jail.conf or jail.d/*.conf (read before jail.local); a failed hostname lookup leaves that entry ineffective with a log warning, so addresses and networks are safer; --tags fail2ban_configure skips the validation.
Molecule default scenario: converge with a custom list; verify that jail.local has the [DEFAULT] line and that the running daemon ignores the configured network on the sshd jail and on the jail.d service jail svc-a; converge with a whitespace entry, a plain string and a semicolon entry, each wrapped so the play passes, asserting that the failure carries the validation message, and verify none of the rejected values reached jail.local.
Compatibility
The first run after upgrading adds the [DEFAULT] section to jail.local, so Fail2Ban restarts once (the existing Restart handler, which stops the jails and starts them again). Later runs are idempotent.
Verified
All pre-commit hooks pass on every commit, and ansible-test sanity passes in the pre-push hook.
CI on the current head: Lint, Build and Molecule are green. Molecule selected the fail2ban scenario and passed converge, idempotence and verify, including the new rejection cases and the fail2ban-client get <jail> ignoreip checks.
The real validate.yml task run on 16 cases with the role defaults loaded: accepts the default, an extra network, an IPv6 prefix, a hostname, a value containing #, and an empty list; rejects a plain string, a mapping, an integer entry, a null entry, an embedded space, a trailing newline, an empty string, and ; or % in an entry.
Two behaviours of Fail2Ban 1.1.0 were checked in its source: inline_comment_prefixes = ";" and BasicInterpolation in the config parser, and the read order jail.conf, jail.d/*.conf, jail.local, jail.d/*.local.
Not verified
The empty list (ignoreip = with nothing after it) is rendered as expected but is not covered by Molecule: testing it needs a second jail.local rewrite between converge and verify.
The Fail2Ban restart on the first upgrade run of an existing host (Molecule starts from a fresh container).
Assisted-by: Claude Code
Closes #155
## What
`fail2ban_ignoreip`: a list of addresses or networks written as `ignoreip` in a new `[DEFAULT]` section of `jail.local`. The default is Fail2Ban's own (`127.0.0.1/8`, `::1`), so nothing changes unless a consumer sets it.
## Why
The role had no way to keep a trusted address from being banned. A mistyped key or a looping health check from the machine that runs Ansible, or from a CI runner, can get that address banned and lock automation out of the host. `[DEFAULT]` covers both the jails of `fail2ban_jails` and the service jails that other roles add with `tasks_from: service_jail` (written to `jail.d`); a per-jail `ignoreip` would need repeating on every jail and would miss service jails.
## Changes
- `defaults/main.yml`, `templates/jail.local.j2`: the variable and the `[DEFAULT]` block.
- `tasks/validate.yml`: the value must be a list of non-empty strings (`argument_specs` accepts a plain string for a list option and leaves it a string, and accepts numbers and null in the list, so the type is checked here first). Entries must hold no whitespace (they are joined with spaces), no `;` (after whitespace it starts an inline comment in Fail2Ban's config files, which drops the rest of the line without an error) and no `%` (interpolation syntax, which fails the whole config after `jail.local` is written). The pattern ends in `\Z`, not `$`.
- `meta/argument_specs.yml` (typed option; the role description mentions the validation), README, changelog fragment (`minor_changes`).
- Documented limits: `service_jail` does not read the variable; the value replaces an `ignoreip` set in `jail.conf` or `jail.d/*.conf` (read before `jail.local`); a failed hostname lookup leaves that entry ineffective with a log warning, so addresses and networks are safer; `--tags fail2ban_configure` skips the validation.
- Molecule `default` scenario: converge with a custom list; verify that `jail.local` has the `[DEFAULT]` line and that the running daemon ignores the configured network on the `sshd` jail and on the `jail.d` service jail `svc-a`; converge with a whitespace entry, a plain string and a semicolon entry, each wrapped so the play passes, asserting that the failure carries the validation message, and verify none of the rejected values reached `jail.local`.
## Compatibility
The first run after upgrading adds the `[DEFAULT]` section to `jail.local`, so Fail2Ban restarts once (the existing `Restart` handler, which stops the jails and starts them again). Later runs are idempotent.
## Verified
- All pre-commit hooks pass on every commit, and `ansible-test sanity` passes in the pre-push hook.
- CI on the current head: Lint, Build and Molecule are green. Molecule selected the `fail2ban` scenario and passed converge, idempotence and verify, including the new rejection cases and the `fail2ban-client get <jail> ignoreip` checks.
- The real `validate.yml` task run on 16 cases with the role defaults loaded: accepts the default, an extra network, an IPv6 prefix, a hostname, a value containing `#`, and an empty list; rejects a plain string, a mapping, an integer entry, a null entry, an embedded space, a trailing newline, an empty string, and `;` or `%` in an entry.
- Two behaviours of Fail2Ban 1.1.0 were checked in its source: `inline_comment_prefixes = ";"` and `BasicInterpolation` in the config parser, and the read order `jail.conf`, `jail.d/*.conf`, `jail.local`, `jail.d/*.local`.
## Not verified
- The empty list (`ignoreip = ` with nothing after it) is rendered as expected but is not covered by Molecule: testing it needs a second `jail.local` rewrite between converge and verify.
- The Fail2Ban restart on the first upgrade run of an existing host (Molecule starts from a fresh container).
Assisted-by: Claude Code
Write fail2ban_ignoreip as ignoreip in the [DEFAULT] section of jail.local, so
it applies to every jail, the service jails in jail.d included. The default is
Fail2Ban's own (127.0.0.1/8 and ::1). Entries are validated (no whitespace,
\Z-anchored) because they are joined into one line.
The first run after upgrading adds the [DEFAULT] section and restarts Fail2Ban
once.
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Q72rsMCgwaR1sbYZangwbp
Review of head 57b15df. No blocking issues. The change is mergeable; I'd like the first item below fixed before merge.
What checks out
[DEFAULT] in jail.local is the right place: it reaches both the fail2ban_jails jails and the jail.d service jails.
The Molecule verify asks the running daemon (fail2ban-client get <jail> ignoreip) for both sshd and svc-a, so it proves the setting takes effect, not just that the file was written.
Validation runs before configure, so a rejected value never reaches jail.local. \Z is the correct anchor.
Conventions: Conventional Commit, changelog fragment, README, defaults and argument_specs agree. Build, Lint and Molecule are green.
Please fix
A scalar string such as fail2ban_ignoreip: "1.2.3.4" is probably accepted by argument_specs, which splits a str on commas for type: list. The variable then stays a string, select('match') and join(' ') iterate per character, and a plain Jinja render gives ignoreip = 1 . 2 . 3 . 4. I did not run this in Ansible, so please confirm. Suggested fix: add fail2ban_ignoreip is sequence and is not string to the assert in tasks/validate.yml. Then the comment "the type is argument_specs' job" holds.
Nits
2. README: the exemption only exists once the main entry point has written jail.local on that host. service_jail neither reads fail2ban_ignoreip nor runs validate.yml, so a host using only service_jail gets no exemption. Worth one sentence.
3. README: Fail2Ban resolves hostnames when the jail starts, and a DNS failure leaves the entry silently ineffective. Recommend IPs or CIDR over hostnames.
4. The empty-list case (ignoreip = with a trailing space) has no Molecule coverage. Optional.
5. null or non-string entries probably fail with a TypeError in the match filter. That still happens before anything is written, so it only costs a poor error message.
6. Cosmetic: the role description line in argument_specs.yml is much longer than its neighbours, and the PR body has a stray blank line that splits the "Verified" list.
Not verified by me
Real Fail2Ban behaviour (I did not run Fail2Ban; precedence and empty-list handling are from its docs).
The fail2ban-client get ignoreip output format beyond what the green Molecule run implies.
The first-upgrade restart on an existing host, which the PR itself lists as unverified.
Review of head 57b15df. No blocking issues. The change is mergeable; I'd like the first item below fixed before merge.
**What checks out**
- `[DEFAULT]` in `jail.local` is the right place: it reaches both the `fail2ban_jails` jails and the `jail.d` service jails.
- The Molecule verify asks the running daemon (`fail2ban-client get <jail> ignoreip`) for both `sshd` and `svc-a`, so it proves the setting takes effect, not just that the file was written.
- Validation runs before `configure`, so a rejected value never reaches `jail.local`. `\Z` is the correct anchor.
- Conventions: Conventional Commit, changelog fragment, README, defaults and `argument_specs` agree. Build, Lint and Molecule are green.
**Please fix**
1. A scalar string such as `fail2ban_ignoreip: "1.2.3.4"` is probably accepted by `argument_specs`, which splits a str on commas for `type: list`. The variable then stays a string, `select('match')` and `join(' ')` iterate per character, and a plain Jinja render gives `ignoreip = 1 . 2 . 3 . 4`. I did not run this in Ansible, so please confirm. Suggested fix: add `fail2ban_ignoreip is sequence and is not string` to the assert in `tasks/validate.yml`. Then the comment "the type is argument_specs' job" holds.
**Nits**
2. README: the exemption only exists once the main entry point has written `jail.local` on that host. `service_jail` neither reads `fail2ban_ignoreip` nor runs `validate.yml`, so a host using only `service_jail` gets no exemption. Worth one sentence.
3. README: Fail2Ban resolves hostnames when the jail starts, and a DNS failure leaves the entry silently ineffective. Recommend IPs or CIDR over hostnames.
4. The empty-list case (`ignoreip = ` with a trailing space) has no Molecule coverage. Optional.
5. `null` or non-string entries probably fail with a `TypeError` in the `match` filter. That still happens before anything is written, so it only costs a poor error message.
6. Cosmetic: the role description line in `argument_specs.yml` is much longer than its neighbours, and the PR body has a stray blank line that splits the "Verified" list.
**Not verified by me**
- Real Fail2Ban behaviour (I did not run Fail2Ban; precedence and empty-list handling are from its docs).
- The `fail2ban-client get ignoreip` output format beyond what the green Molecule run implies.
- The first-upgrade restart on an existing host, which the PR itself lists as unverified.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
argument_specs accepts a plain string for a list option and leaves it a string,
and accepts a list holding a number or null. The pattern check then iterated a
string per character and rendered "1 . 2 . 3 . 4", or died with a TypeError on
null. Check the type first (assert stops at the first false item).
Also refuse ";" and "%" in an entry: Fail2Ban's config parser treats ";" after
whitespace as an inline comment, which drops the rest of the ignoreip line
without an error, and "%" as interpolation syntax, which fails the whole config
after jail.local is written. Add Molecule cases for a scalar string and a
semicolon entry.
Document what review found: service_jail does not read the variable, the
[DEFAULT] value replaces an ignoreip set in jail.conf or jail.d/*.conf, a failed
hostname lookup leaves the entry ineffective with a log warning (addresses and
networks are safer), and --tags fail2ban_configure skips the validation.
Assisted-by: Claude Code
The three rejection cases only printed "Rejected as expected", so they would
also pass when the role failed for another reason. Assert that the failure
carries the validation message of fail2ban_ignoreip.
Assisted-by: Claude Code
Thanks for the review. Pushed 9dcb933 (fast-forward; your two merges of main are included). Lint, Build and Molecule are green on it.
Fixed
Confirmed in Ansible before changing anything: argument_specs accepts "1.2.3.4" for the list option and the variable stays a string, so the old assert passed and the template rendered 1 . 2 . 3 . 4. validate.yml now checks that the value is a list, with no mapping and no non-string entries, before the pattern check (an assert stops at the first false item, so the later items never see a value they cannot handle).
Numbers and null in the list now fail with the validation message instead of a TypeError. That is the same change.
README: service_jail does not read fail2ban_ignoreip, so a host that uses only service_jail has no exemption.
README and argument_specs: prefer addresses and networks to hostnames. I checked the source: a failed lookup logs a warning (Unable to find a corresponding IP address for ...), so I did not call it silent.
The long description line is wrapped and the PR body no longer splits the Verified list.
Also found while checking your points (Fail2Ban 1.1.0 source)
The config parser sets inline_comment_prefixes = ";", so an entry starting with ; would drop the rest of the ignoreip line without an error, and -t cannot see it. % is interpolation syntax and fails the whole config after jail.local is written. Both are now refused. I left # allowed: it is not an inline comment prefix there.
jail.d/*.conf is read before jail.local, so the new [DEFAULT] value replaces an ignoreip set there. That is documented now, as is the fact that --tags fail2ban_configure skips the validation.
Tests: new rejection cases for a plain string and a ; entry. All three rejection cases now assert that the failure carries the validation message, so they cannot pass for another reason.
Not done (4): the empty-list case has no Molecule test. It would need a second jail.local rewrite between converge and verify. I checked the rendering locally (ignoreip = ) and listed it under "Not verified" in the body.
Assisted-by: Claude Code
Thanks for the review. Pushed `9dcb933` (fast-forward; your two merges of `main` are included). Lint, Build and Molecule are green on it.
**Fixed**
1. Confirmed in Ansible before changing anything: `argument_specs` accepts `"1.2.3.4"` for the list option and the variable stays a string, so the old assert passed and the template rendered `1 . 2 . 3 . 4`. `validate.yml` now checks that the value is a list, with no mapping and no non-string entries, before the pattern check (an `assert` stops at the first false item, so the later items never see a value they cannot handle).
5. Numbers and `null` in the list now fail with the validation message instead of a `TypeError`. That is the same change.
2. README: `service_jail` does not read `fail2ban_ignoreip`, so a host that uses only `service_jail` has no exemption.
3. README and `argument_specs`: prefer addresses and networks to hostnames. I checked the source: a failed lookup logs a warning (`Unable to find a corresponding IP address for ...`), so I did not call it silent.
6. The long description line is wrapped and the PR body no longer splits the Verified list.
**Also found while checking your points (Fail2Ban 1.1.0 source)**
- The config parser sets `inline_comment_prefixes = ";"`, so an entry starting with `;` would drop the rest of the `ignoreip` line without an error, and `-t` cannot see it. `%` is interpolation syntax and fails the whole config after `jail.local` is written. Both are now refused. I left `#` allowed: it is not an inline comment prefix there.
- `jail.d/*.conf` is read before `jail.local`, so the new `[DEFAULT]` value replaces an `ignoreip` set there. That is documented now, as is the fact that `--tags fail2ban_configure` skips the validation.
**Tests:** new rejection cases for a plain string and a `;` entry. All three rejection cases now assert that the failure carries the validation message, so they cannot pass for another reason.
**Not done (4):** the empty-list case has no Molecule test. It would need a second `jail.local` rewrite between converge and verify. I checked the rendering locally (`ignoreip = `) and listed it under "Not verified" in the body.
Assisted-by: Claude Code
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Closes #155
What
fail2ban_ignoreip: a list of addresses or networks written asignoreipin a new[DEFAULT]section ofjail.local. The default is Fail2Ban's own (127.0.0.1/8,::1), so nothing changes unless a consumer sets it.Why
The role had no way to keep a trusted address from being banned. A mistyped key or a looping health check from the machine that runs Ansible, or from a CI runner, can get that address banned and lock automation out of the host.
[DEFAULT]covers both the jails offail2ban_jailsand the service jails that other roles add withtasks_from: service_jail(written tojail.d); a per-jailignoreipwould need repeating on every jail and would miss service jails.Changes
defaults/main.yml,templates/jail.local.j2: the variable and the[DEFAULT]block.tasks/validate.yml: the value must be a list of non-empty strings (argument_specsaccepts a plain string for a list option and leaves it a string, and accepts numbers and null in the list, so the type is checked here first). Entries must hold no whitespace (they are joined with spaces), no;(after whitespace it starts an inline comment in Fail2Ban's config files, which drops the rest of the line without an error) and no%(interpolation syntax, which fails the whole config afterjail.localis written). The pattern ends in\Z, not$.meta/argument_specs.yml(typed option; the role description mentions the validation), README, changelog fragment (minor_changes).service_jaildoes not read the variable; the value replaces anignoreipset injail.conforjail.d/*.conf(read beforejail.local); a failed hostname lookup leaves that entry ineffective with a log warning, so addresses and networks are safer;--tags fail2ban_configureskips the validation.defaultscenario: converge with a custom list; verify thatjail.localhas the[DEFAULT]line and that the running daemon ignores the configured network on thesshdjail and on thejail.dservice jailsvc-a; converge with a whitespace entry, a plain string and a semicolon entry, each wrapped so the play passes, asserting that the failure carries the validation message, and verify none of the rejected values reachedjail.local.Compatibility
The first run after upgrading adds the
[DEFAULT]section tojail.local, so Fail2Ban restarts once (the existingRestarthandler, which stops the jails and starts them again). Later runs are idempotent.Verified
ansible-test sanitypasses in the pre-push hook.fail2banscenario and passed converge, idempotence and verify, including the new rejection cases and thefail2ban-client get <jail> ignoreipchecks.validate.ymltask run on 16 cases with the role defaults loaded: accepts the default, an extra network, an IPv6 prefix, a hostname, a value containing#, and an empty list; rejects a plain string, a mapping, an integer entry, a null entry, an embedded space, a trailing newline, an empty string, and;or%in an entry.inline_comment_prefixes = ";"andBasicInterpolationin the config parser, and the read orderjail.conf,jail.d/*.conf,jail.local,jail.d/*.local.Not verified
ignoreip =with nothing after it) is rendered as expected but is not covered by Molecule: testing it needs a secondjail.localrewrite between converge and verify.Assisted-by: Claude Code
Review of head
57b15df. No blocking issues. The change is mergeable; I'd like the first item below fixed before merge.What checks out
[DEFAULT]injail.localis the right place: it reaches both thefail2ban_jailsjails and thejail.dservice jails.fail2ban-client get <jail> ignoreip) for bothsshdandsvc-a, so it proves the setting takes effect, not just that the file was written.configure, so a rejected value never reachesjail.local.\Zis the correct anchor.argument_specsagree. Build, Lint and Molecule are green.Please fix
fail2ban_ignoreip: "1.2.3.4"is probably accepted byargument_specs, which splits a str on commas fortype: list. The variable then stays a string,select('match')andjoin(' ')iterate per character, and a plain Jinja render givesignoreip = 1 . 2 . 3 . 4. I did not run this in Ansible, so please confirm. Suggested fix: addfail2ban_ignoreip is sequence and is not stringto the assert intasks/validate.yml. Then the comment "the type is argument_specs' job" holds.Nits
2. README: the exemption only exists once the main entry point has written
jail.localon that host.service_jailneither readsfail2ban_ignoreipnor runsvalidate.yml, so a host using onlyservice_jailgets no exemption. Worth one sentence.3. README: Fail2Ban resolves hostnames when the jail starts, and a DNS failure leaves the entry silently ineffective. Recommend IPs or CIDR over hostnames.
4. The empty-list case (
ignoreip =with a trailing space) has no Molecule coverage. Optional.5.
nullor non-string entries probably fail with aTypeErrorin thematchfilter. That still happens before anything is written, so it only costs a poor error message.6. Cosmetic: the role description line in
argument_specs.ymlis much longer than its neighbours, and the PR body has a stray blank line that splits the "Verified" list.Not verified by me
fail2ban-client get ignoreipoutput format beyond what the green Molecule run implies.🤖 Generated with Claude Code
Thanks for the review. Pushed
9dcb933(fast-forward; your two merges ofmainare included). Lint, Build and Molecule are green on it.Fixed
argument_specsaccepts"1.2.3.4"for the list option and the variable stays a string, so the old assert passed and the template rendered1 . 2 . 3 . 4.validate.ymlnow checks that the value is a list, with no mapping and no non-string entries, before the pattern check (anassertstops at the first false item, so the later items never see a value they cannot handle).nullin the list now fail with the validation message instead of aTypeError. That is the same change.service_jaildoes not readfail2ban_ignoreip, so a host that uses onlyservice_jailhas no exemption.argument_specs: prefer addresses and networks to hostnames. I checked the source: a failed lookup logs a warning (Unable to find a corresponding IP address for ...), so I did not call it silent.Also found while checking your points (Fail2Ban 1.1.0 source)
inline_comment_prefixes = ";", so an entry starting with;would drop the rest of theignoreipline without an error, and-tcannot see it.%is interpolation syntax and fails the whole config afterjail.localis written. Both are now refused. I left#allowed: it is not an inline comment prefix there.jail.d/*.confis read beforejail.local, so the new[DEFAULT]value replaces anignoreipset there. That is documented now, as is the fact that--tags fail2ban_configureskips the validation.Tests: new rejection cases for a plain string and a
;entry. All three rejection cases now assert that the failure carries the validation message, so they cannot pass for another reason.Not done (4): the empty-list case has no Molecule test. It would need a second
jail.localrewrite between converge and verify. I checked the rendering locally (ignoreip =) and listed it under "Not verified" in the body.Assisted-by: Claude Code