canonical / cloud-init

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

set_hostname does not set the hostname before the initial DHCP communication #4049

Closed ubuntu-server-builder closed 1 year ago

ubuntu-server-builder commented 1 year ago

This bug was originally filed in Launchpad as LP: #1998640

Launchpad details
affected_projects = []
assignee = None
assignee_name = None
date_closed = 2023-02-05T04:17:21.106735+00:00
date_created = 2022-12-02T18:15:20.632885+00:00
date_fix_committed = None
date_fix_released = None
id = 1998640
importance = undecided
is_complete = True
lp_url = https://bugs.launchpad.net/cloud-init/+bug/1998640
milestone = None
owner = sw2828
owner_name = Jack Pylie
private = False
status = expired
submitter = sw2828
submitter_name = Jack Pylie
tags = []
duplicates = []

Launchpad user Jack Pylie(sw2828) wrote on 2022-12-02T18:15:20.632885+00:00

Per the doc(https://cloudinit.readthedocs.io/en/22.3.4/topics/modules.html#set-hostname), with the cloud-config below, when using "fqdn" or "hostname", the desired hostname should be set before the initial DHCP communication so that DDNS can update the DNS record with the proper hostname. This is not happening in our environment. "ubuntu" is sent to the DNS server instead of the new hostname of the guest.

The DNS does get updated after we reboot the guest a second time. We have added a workaround for the 2nd reboot(see below power_state). I have also added the kead dhcp4 logs showing the behavior.

My issue is similar to: Bug #1600766 status: Confirmed → Won't Fix Bug #1746455 status: Fixed Released

Environment Info

Hypervisor: KVM Hypervisor OS: Red Hat Enterprise Linux 8.6 Guest OS:Ubuntu 22.04.1 LTS cloud-init --version: /usr/bin/cloud-init 22.3.4-0ubuntu1~22.04.1 Data Source: nocloud

cloud-config

preserve_hostname: false fqdn: ${ guest_hostname }.${ guest_subdomain }.test.lan prefer_fqdn_over_hostname: true users:

set hostname document stating "desired hostname is applied before any DHCP requests are performed"

"This will occur on datasources like nocloud and ovf where metadata and user data are available locally. This ensures that the desired hostname is applied before any DHCP requests are performed on these platforms where dynamic DNS is based on initial hostname."

kea dhcp4 logs:

/var/lib/kea # grep 52:54:00:ca:dd:19 * dhcp4.leases:10.61.229.229,52:54:00:ca:dd:19,ff:b5:5e:67:ff:00:02:00:00:ab:11:2b:2f:f0:f1:3d:27:d9:a1,43200,1670044228,5,1,1,ubuntu.061asd.zebra.lan,0, #1st boot with default "ubuntu" hostname dhcp4.leases:10.61.229.229,52:54:00:ca:dd:19,ff:b5:5e:67:ff:00:02:00:00:ab:11:2b:2f:f0:f1:3d:27:d9:a1,0,1670001028,5,1,1,ubuntu.061asd.zebra.lan,0, #Release is sent when reboot is initiated on guest, valid_lifetime set to 0 dhcp4.leases:10.61.229.230,52:54:00:ca:dd:19,ff:b5:5e:67:ff:00:02:00:00:ab:11:2b:2f:f0:f1:3d:27:d9:a1,43200,1670044253,5,1,1,p061u004.061asd.zebra.lan.,0, #2nd boot sends proper hostname to register to DNS

ubuntu-server-builder commented 1 year ago

Launchpad user Jack Pylie(sw2828) wrote on 2022-12-02T18:15:20.632885+00:00

Launchpad attachments: logs

ubuntu-server-builder commented 1 year ago

Launchpad user Brett Holman(holmanb) wrote on 2022-12-06T15:13:13.298535+00:00

This might not be possible in this case, since you are using NoCloud "net", which does not have userdata available locally during boot.

The docs don't make that terribly clear, this might require a doc clarification.

Could you please include your /var/log/cloud-init.log?

ubuntu-server-builder commented 1 year ago

Launchpad user Launchpad Janitor(janitor) wrote on 2023-02-05T04:17:20.922129+00:00

[Expired for cloud-init because there has been no activity for 60 days.]