Cloud-init creates /etc/apt/sources.list.d/ubuntu.sources even if /etc/apt/sources.list exists

Bug #2045086 reported by Heinrich Schuchardt
20
This bug affects 3 people
Affects Status Importance Assigned to Milestone
cloud-init (Ubuntu)
Fix Released
Medium
Alberto Contreras

Bug Description

The RISC-V preinstalled server image noble-preinstalled-server-riscv64.img has a file /etc/apt/sources.list.

After first boot I additionally find /etc/apt/sources.list.d/ubuntu.sources which is created by cloud-init.

This leads to failures in 'apt-get update' like:

W: Target CNF (multiverse/cnf/Commands-riscv64) is configured multiple times in /etc/apt/sources.list:41 and /etc/apt/sources.list.d/ubuntu.sources:2
W: Target CNF (multiverse/cnf/Commands-all) is configured multiple times in /etc/apt/sources.list:41 and /etc/apt/sources.list.d/ubuntu.sources:2

Cloud-init should avoid creating duplicate apt source. If /etc/apt/sources.list already exists, cloud-init should not try to generate /etc/apt/sources.list.d/ubuntu.sources.

Revision history for this message
Launchpad Janitor (janitor) wrote :

Status changed to 'Confirmed' because the bug affects multiple users.

Changed in cloud-init (Ubuntu):
status: New → Confirmed
Revision history for this message
Alberto Contreras (aciba) wrote :

Thanks, Heinrich, for reporting this and making cloud-init better.

I can confirm this is reproducible in noble. Those warnings are not hard errors and apt works correctly, but having two sources of config could lead to conflicts / unexpected behavior / hard apt errors in the future. In addition to that, the warnings could be a concern for users, so I think this is a bug that has to be fixed.

cloud-init upstream bug: https://github.com/canonical/cloud-init/issues/4691

Changed in cloud-init (Ubuntu):
status: Confirmed → Triaged
importance: Undecided → Medium
Revision history for this message
Chad Smith (chad.smith) wrote :

This appears to be an artifact of the image creation process. I can also confirm that the /etc/apt/sources.list file in the image has a timestamp at the image creation date, not the cloud-init launch date. And cloud-init only writes /etc/apt/sources.list.d/ubuntu.sources.

root@unique-terrapin:~# lsb_release -sc
No LSB modules are available.
noble
root@unique-terrapin:~# cat /etc/cloud/build.info
build_name: server
serial: 20231213
root@unique-terrapin:~# ls -l --full-time /etc/apt/sources.list
-rw-r--r-- 1 root root 2403 2023-12-13 08:38:45.000000000 +0000 /etc/apt/sources.list
root@unique-terrapin:~# egrep 'Writing.*/etc' /var/log/cloud-init.log
2023-12-14 19:54:04,260 - util.py[DEBUG]: Writing to /etc/hostname - wb: [644] 16 bytes
2023-12-14 19:54:04,363 - util.py[DEBUG]: Writing to /etc/netplan/50-cloud-init.yaml - wb: [600] 389 bytes
2023-12-14 19:54:05,613 - util.py[DEBUG]: Writing to /etc/sudoers.d/90-cloud-init-users - wb: [440] 131 bytes
2023-12-14 19:54:09,640 - util.py[DEBUG]: Writing to /etc/apt/sources.list.d/ubuntu.sources - wb: [644] 3097 bytes

Revision history for this message
Alberto Contreras (aciba) wrote :
Changed in cloud-init (Ubuntu):
assignee: nobody → Alberto Contreras (aciba)
status: Triaged → Fix Committed
Revision history for this message
Launchpad Janitor (janitor) wrote :

This bug was fixed in the package cloud-init - 24.1~2gb6a1c635-0ubuntu1

---------------
cloud-init (24.1~2gb6a1c635-0ubuntu1) noble; urgency=medium

  * Upstream snapshot based on upstream/main at b6a1c635.
    - Bugs fixed in this snapshot: (LP: #2045086, #1951639)

 -- Alberto Contreras <email address hidden> Thu, 04 Jan 2024 10:16:55 +0100

Changed in cloud-init (Ubuntu):
status: Fix Committed → Fix Released
Revision history for this message
Chad Smith (chad.smith) wrote :

Expect cloudimages with /etc/cloud/build.info serial number greater than `serial: 20241010` to have a fix landed. cloud-init 24.1~2 is already released and available in noble-updates

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Duplicates of this bug

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.