canonical / cloud-init

Official upstream for the cloud-init: cloud instance initialization
https://cloud-init.io/
Other
2.85k stars 854 forks source link

uses_systemd in cloudinit.distros doesn't properly detect systemd if VM isn't running #5518

Open RussellAult opened 1 month ago

RussellAult commented 1 month ago

Bug report

https://github.com/canonical/cloud-init/blob/e0e6a427fdc6826bf7b11d52157a1c5f9b3dde4d/cloudinit/distros/__init__.py#L1608-L1613 returns a "false False" if the the target VM is being edited using offline tools (e.g. libguestfs), since /run is only populated on a running system

Steps to reproduce the problem

virt-customize -a <debian_cloud_image>.qcow2 --run-command 'cloud-init clean --machine-id' should produce an /etc/machine-id of undefined; instead it deletes the file entirely (the non-systemd result)

Environment details

holmanb commented 1 month ago

This isn't a valid bug report.

aciba90 commented 1 month ago

Thanks, @RussellAult, for reporting this.

cloud-init clean runs under the assumption of the system running. As a workaround, one can manually modify the machine-id with:

virt-customize -a $IMG \
  --run-command 'cp /etc/machine-id /etc/machine-id.bak' \
  --run-command 'echo "undefined" > /etc/machine-id'

Doing a quick search, it looks like it is quite difficult to detect if a system is configured with systemd as the init system without the systemd running and for any distro and version.