apt-daily.service (the daily package-list refresh and download) is Type=oneshot, and systemd gives a oneshot unit no start timeout by default. If the apt-get update it runs hangs, nothing ever stops it, and it keeps the apt/dpkg lock. Every later apt command on the host then waits for the lock or fails with "Could not get lock", including the package update and the package installation this role does, and unattended-upgrades.
I saw it once: an apt-get update hung on two dead mirror connections (sockets stuck in CLOSE-WAIT) for 2 days and 8 hours, held the lock, and made a weekly update job and a build that needed apt fail until the process was killed by hand. A timeout would have stopped the unit and released the lock after an hour.
Out of scope: apt-daily-upgrade.service, which installs packages. Stopping it halfway through could leave dpkg in a half-configured state, so it is left alone on purpose.
Proposal
New input system_baseline_apt_daily_timeout (string, a systemd time span such as 1h or 90min; default empty, which leaves the host alone, so existing consumers see no change). When set, a drop-in /etc/systemd/system/apt-daily.service.d/10-timeout.conf with [Service] and TimeoutStartSec=<value>, written after creating the drop-in directory (ansible.builtin.copy does not create the directory of its destination, and a dry run does not show that it is missing), and a daemon-reload handler. When it is empty, the role does not manage the file. Where to run it in main.yml: a tagged task file (apt-daily-timeout) next to the other systemd drop-ins.
Why only apt-daily.service: it never runs dpkg, so the timeout can stop it safely; systemd stops the unit and everything in its cgroup, which includes the hung apt-get.
Acceptance criteria
With a value set (for example 1h), the drop-in exists with mode 0644 and the content above, and after the reload systemctl show -p TimeoutStartUSec apt-daily.service in verify.yml reports one hour (the scenario's systemd loads drop-ins after the handler's daemon-reload, as the existing tests of drop-ins do).
With the default (empty), no drop-in is written and no directory is created; a second converge changes nothing (Molecule idempotence).
A value that is not a systemd time span ("soon") is refused with a message that names the variable (validation in tasks/validate.yml, and the spec holds type: str).
argument_specs.yml and the README variable table list the input and its default; ansible-test sanity, ansible-lint and yamllint are clean; a minor_changes fragment is added.
Not verified
That a drop-in for apt-daily.service is read on every Ubuntu release you support: I run the same drop-in on Ubuntu 24.04 guests and on Debian 12 and 13 hosts; I have not run this role.
That apt-daily.service exists in the Molecule image (it may not be installed in a minimal image; a stub unit file would do, as the other tests of this role use).
Whether the default should stay empty (no change for anyone) or become a safe value such as 1h; I propose empty because a role default that adds a drop-in on every host is a behaviour change.
Questions for the maintainer
Empty by default, or 1h?
Is system_baseline the right role, or would you rather have this in a separate small role for apt timers?
Assisted-by: Claude Code
## Problem
`apt-daily.service` (the daily package-list refresh and download) is `Type=oneshot`, and systemd gives a `oneshot` unit no start timeout by default. If the `apt-get update` it runs hangs, nothing ever stops it, and it keeps the apt/dpkg lock. Every later `apt` command on the host then waits for the lock or fails with "Could not get lock", including the package update and the package installation this role does, and unattended-upgrades.
I saw it once: an `apt-get update` hung on two dead mirror connections (sockets stuck in `CLOSE-WAIT`) for 2 days and 8 hours, held the lock, and made a weekly update job and a build that needed `apt` fail until the process was killed by hand. A timeout would have stopped the unit and released the lock after an hour.
Out of scope: `apt-daily-upgrade.service`, which installs packages. Stopping it halfway through could leave dpkg in a half-configured state, so it is left alone on purpose.
## Proposal
New input `system_baseline_apt_daily_timeout` (string, a systemd time span such as `1h` or `90min`; default empty, which leaves the host alone, so existing consumers see no change). When set, a drop-in `/etc/systemd/system/apt-daily.service.d/10-timeout.conf` with `[Service]` and `TimeoutStartSec=<value>`, written after creating the drop-in directory (`ansible.builtin.copy` does not create the directory of its destination, and a dry run does not show that it is missing), and a `daemon-reload` handler. When it is empty, the role does not manage the file. Where to run it in `main.yml`: a tagged task file (`apt-daily-timeout`) next to the other systemd drop-ins.
Why only `apt-daily.service`: it never runs dpkg, so the timeout can stop it safely; systemd stops the unit and everything in its cgroup, which includes the hung `apt-get`.
## Acceptance criteria
- [ ] With a value set (for example `1h`), the drop-in exists with mode `0644` and the content above, and after the reload `systemctl show -p TimeoutStartUSec apt-daily.service` in `verify.yml` reports one hour (the scenario's systemd loads drop-ins after the handler's `daemon-reload`, as the existing tests of drop-ins do).
- [ ] With the default (empty), no drop-in is written and no directory is created; a second converge changes nothing (Molecule idempotence).
- [ ] A value that is not a systemd time span (`"soon"`) is refused with a message that names the variable (validation in `tasks/validate.yml`, and the spec holds `type: str`).
- [ ] `argument_specs.yml` and the README variable table list the input and its default; `ansible-test sanity`, ansible-lint and yamllint are clean; a `minor_changes` fragment is added.
## Not verified
- That a drop-in for `apt-daily.service` is read on every Ubuntu release you support: I run the same drop-in on Ubuntu 24.04 guests and on Debian 12 and 13 hosts; I have not run this role.
- That `apt-daily.service` exists in the Molecule image (it may not be installed in a minimal image; a stub unit file would do, as the other tests of this role use).
- Whether the default should stay empty (no change for anyone) or become a safe value such as `1h`; I propose empty because a role default that adds a drop-in on every host is a behaviour change.
## Questions for the maintainer
- Empty by default, or `1h`?
- Is `system_baseline` the right role, or would you rather have this in a separate small role for apt timers?
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.
Problem
apt-daily.service(the daily package-list refresh and download) isType=oneshot, and systemd gives aoneshotunit no start timeout by default. If theapt-get updateit runs hangs, nothing ever stops it, and it keeps the apt/dpkg lock. Every lateraptcommand on the host then waits for the lock or fails with "Could not get lock", including the package update and the package installation this role does, and unattended-upgrades.I saw it once: an
apt-get updatehung on two dead mirror connections (sockets stuck inCLOSE-WAIT) for 2 days and 8 hours, held the lock, and made a weekly update job and a build that neededaptfail until the process was killed by hand. A timeout would have stopped the unit and released the lock after an hour.Out of scope:
apt-daily-upgrade.service, which installs packages. Stopping it halfway through could leave dpkg in a half-configured state, so it is left alone on purpose.Proposal
New input
system_baseline_apt_daily_timeout(string, a systemd time span such as1hor90min; default empty, which leaves the host alone, so existing consumers see no change). When set, a drop-in/etc/systemd/system/apt-daily.service.d/10-timeout.confwith[Service]andTimeoutStartSec=<value>, written after creating the drop-in directory (ansible.builtin.copydoes not create the directory of its destination, and a dry run does not show that it is missing), and adaemon-reloadhandler. When it is empty, the role does not manage the file. Where to run it inmain.yml: a tagged task file (apt-daily-timeout) next to the other systemd drop-ins.Why only
apt-daily.service: it never runs dpkg, so the timeout can stop it safely; systemd stops the unit and everything in its cgroup, which includes the hungapt-get.Acceptance criteria
1h), the drop-in exists with mode0644and the content above, and after the reloadsystemctl show -p TimeoutStartUSec apt-daily.serviceinverify.ymlreports one hour (the scenario's systemd loads drop-ins after the handler'sdaemon-reload, as the existing tests of drop-ins do)."soon") is refused with a message that names the variable (validation intasks/validate.yml, and the spec holdstype: str).argument_specs.ymland the README variable table list the input and its default;ansible-test sanity, ansible-lint and yamllint are clean; aminor_changesfragment is added.Not verified
apt-daily.serviceis read on every Ubuntu release you support: I run the same drop-in on Ubuntu 24.04 guests and on Debian 12 and 13 hosts; I have not run this role.apt-daily.serviceexists in the Molecule image (it may not be installed in a minimal image; a stub unit file would do, as the other tests of this role use).1h; I propose empty because a role default that adds a drop-in on every host is a behaviour change.Questions for the maintainer
1h?system_baselinethe right role, or would you rather have this in a separate small role for apt timers?Assisted-by: Claude Code