Hash sum mismatch during `packages` module run if primary APT source was changed by `apt` module
Bug report
If the apt module of cloud-init is used to modify the primary APT source URI, and the packages module is configured to install packages, a series of errors can be seen, such as Hash sum mismatch and Unexpected file size. This is caused by package_update defaulting to false, meaning that the local APT state contains package lists from a mirror other than the one being queried. If these mirrors aren't perfectly synchronised, errors such as these will appear, and packages will fail to install.
Steps to reproduce the problem
Boot the minimal Ubuntu 24.04 image using the following cloud-config example (results may vary depending on the sync state of the alternate chosen mirror):
#cloud-config
apt:
primary:
- arches: [default]
uri: http://some.other.mirror/ubuntu
packages:
- ca-certificates
- curl
- sudo
This is in contrast to the following cloud-config, which works perfectly every time:
#cloud-config
apt:
primary:
- arches: [default]
uri: http://some.other.mirror/ubuntu
package_update: true
packages:
- ca-certificates
- curl
- sudo
Environment details
- Cloud-init version: 24.3.1-0ubuntu0~24.04.2
- Operating System Distribution: Ubuntu 24.04
- Cloud provider, platform or installer type: NoCloud
cloud-init logs
@MattKobayashi This bug report is incomplete. You need to collect logs for the report. Please do that so we can help resolve this issue.