systemd_hardening lists every service unit file on each run, only to learn whether the roughly ten units in its disable and mask lists are installed. The listing goes through PID 1 and its cost grows with the number of unit files. The role now runs one systemctl show --property=LoadState over the listed units. A unit with no unit file reports not-found and is skipped, as before. systemd_hardening_installed_units keeps its name, so disable_services.yml and mask_services.yml are unchanged (not renamed, to keep the diff to the task). The README, a bugfixes fragment and a Molecule assertion that a listed-but-missing unit (rsh) is skipped and not masked are updated.
Behaviour changes
A template name such as [email protected] in either list now makes the lookup fail (systemctl show exits 1); the old listing matched it. I chose a loud failure over silently skipping a unit the consumer asked to disable. Is that the handling you want, or should templates be skipped or supported?
An instance name such as [email protected] is now matched when its template exists; the listing never matched it.
Verified
pre-commit run (including ansible-lint production profile, yamllint, the changelog-fragment lint and the Conventional Commit check) passes locally. ansible-test sanity runs in the pre-push hook.
On five Ubuntu 24.04 and Debian hosts (systemd 255), the installed set from the new task block equals the set from the old listing for the default lists plus an alias (sshd), a .service suffix, a duplicate and a missing unit. Empty lists, one entry, all-missing entries and check mode also behave correctly.
Result order for an alias: systemctl show -- sshd.service ssh.service returns the target's Id for the alias, so results are paired by position, not by Id.
Not verified
Molecule has not run (CI only); the new assertion has not run.
The role's own --type=service call was never shown to trip a hardware watchdog; only the socket-type listing was measured, so the motivation is a cost argument and not proof for this exact call.
Debian 13 and Ubuntu 22.04 are covered only by the read-only comparison above, not by a role run. A template name was tested to fail as described; instance names beyond one template were tested on one host.
I confirm third-party material is recorded in NOTICE and REUSE.toml, or there is none.
Assisted-by: Claude Code
## What and why
Closes #283
`systemd_hardening` lists every service unit file on each run, only to learn whether the roughly ten units in its disable and mask lists are installed. The listing goes through PID 1 and its cost grows with the number of unit files. The role now runs one `systemctl show --property=LoadState` over the listed units. A unit with no unit file reports `not-found` and is skipped, as before. `systemd_hardening_installed_units` keeps its name, so `disable_services.yml` and `mask_services.yml` are unchanged (not renamed, to keep the diff to the task). The README, a `bugfixes` fragment and a Molecule assertion that a listed-but-missing unit (`rsh`) is skipped and not masked are updated.
**Behaviour changes**
- A template name such as `[email protected]` in either list now makes the lookup fail (`systemctl show` exits 1); the old listing matched it. I chose a loud failure over silently skipping a unit the consumer asked to disable. Is that the handling you want, or should templates be skipped or supported?
- An instance name such as `[email protected]` is now matched when its template exists; the listing never matched it.
## Verified
- `pre-commit run` (including ansible-lint production profile, yamllint, the changelog-fragment lint and the Conventional Commit check) passes locally. `ansible-test sanity` runs in the pre-push hook.
- On five Ubuntu 24.04 and Debian hosts (systemd 255), the installed set from the new task block equals the set from the old listing for the default lists plus an alias (`sshd`), a `.service` suffix, a duplicate and a missing unit. Empty lists, one entry, all-missing entries and check mode also behave correctly.
- Result order for an alias: `systemctl show -- sshd.service ssh.service` returns the target's `Id` for the alias, so results are paired by position, not by `Id`.
## Not verified
- Molecule has not run (CI only); the new assertion has not run.
- The role's own `--type=service` call was never shown to trip a hardware watchdog; only the socket-type listing was measured, so the motivation is a cost argument and not proof for this exact call.
- Debian 13 and Ubuntu 22.04 are covered only by the read-only comparison above, not by a role run. A template name was tested to fail as described; instance names beyond one template were tested on one host.
---
- [x] I confirm third-party material is recorded in `NOTICE` and `REUSE.toml`, or there is none.
Assisted-by: Claude Code
The role listed every service unit file to answer one question: is each
unit in its disable and mask lists installed? The listing keeps PID 1 busy
for as long as the host has unit files. Ask about the listed units only,
with one `systemctl show --property=LoadState`; a unit with no unit file
reports `not-found` and is skipped as before.
An instance name such as [email protected] is now matched when its template
exists. A template name such as [email protected] makes the lookup fail, where
the listing matched it.
Closes#283
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.
What and why
Closes #283
systemd_hardeninglists every service unit file on each run, only to learn whether the roughly ten units in its disable and mask lists are installed. The listing goes through PID 1 and its cost grows with the number of unit files. The role now runs onesystemctl show --property=LoadStateover the listed units. A unit with no unit file reportsnot-foundand is skipped, as before.systemd_hardening_installed_unitskeeps its name, sodisable_services.ymlandmask_services.ymlare unchanged (not renamed, to keep the diff to the task). The README, abugfixesfragment and a Molecule assertion that a listed-but-missing unit (rsh) is skipped and not masked are updated.Behaviour changes
[email protected]in either list now makes the lookup fail (systemctl showexits 1); the old listing matched it. I chose a loud failure over silently skipping a unit the consumer asked to disable. Is that the handling you want, or should templates be skipped or supported?[email protected]is now matched when its template exists; the listing never matched it.Verified
pre-commit run(including ansible-lint production profile, yamllint, the changelog-fragment lint and the Conventional Commit check) passes locally.ansible-test sanityruns in the pre-push hook.sshd), a.servicesuffix, a duplicate and a missing unit. Empty lists, one entry, all-missing entries and check mode also behave correctly.systemctl show -- sshd.service ssh.servicereturns the target'sIdfor the alias, so results are paired by position, not byId.Not verified
--type=servicecall was never shown to trip a hardware watchdog; only the socket-type listing was measured, so the motivation is a cost argument and not proof for this exact call.NOTICEandREUSE.toml, or there is none.Assisted-by: Claude Code