Wrong EC2 hostname set if DHCP Options Set has multiple domain-name
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
cloud-init |
Expired
|
Low
|
Unassigned |
Bug Description
Cloud Provider: AWS.
Cloud-init v. 19.3-2.amzn2.
Config says system_info: distro: amazon
Per https:/
This is with "set-hostname" and "update-hostname" modules enabled, but no other relevant cloud-init config.
For example, if your unqualified hostname is ip-10-30-10-155 and your DHCP Options Set domain-name is "foo.bar.
This problem appears to be due to misinterpretation of the output of the EC2 metadata service for "local-hostname", which responds with output similar to above, but with spaces retained and no truncating, for example: "ip-10-
The cloud-init log output also mentions this problem, for example you might have logs which look like:
Mar 18 00:31:33 cloud-init[3825]: cc_set_
us-west-
Mar 18 00:31:33 cloud-init[3825]: util.py[DEBUG]: Running command ['hostnamectl', 'set-hostname', 'ip-10-
Mar 18 00:31:33 cloud-init[3825]: __init__.py[DEBUG]: Non-persistently setting the system hostname to ip-10-30-
Mar 18 00:31:33 cloud-init[3825]: util.py[DEBUG]: Running command ['hostname', 'ip-10-
st-2.test.
Mar 18 00:31:33 cloud-init[3825]: util.py[WARNING]: Failed to non-persistently adjust the system hostname to ip-10-30-
st.abcdefg.
Mar 18 00:31:33 cloud-init[3825]: util.py[DEBUG]: Failed to non-persistently adjust the system hostname to ip-10-30-
Traceback (most recent call last):
File "/usr/lib/
util.
File "/usr/lib/
cmd=args)
ProcessExecutio
Command: ['hostname', 'ip-10-
Exit code: 1
Reason: -
Stdout:
Stderr: hostname: the specified hostname is invalid
Thanks for taking the time to report this bug. Multiple domain names are currently not supported; the case falls in the warning given in the page you pointed to:
---
Some Linux operating systems accept multiple domain names separated by spaces. However, other Linux operating systems and Windows treat the value as a single domain, which results in unexpected behavior.
---
I'm not sure of what the Linux distributions supporting multiple domain names are doing; I imagine the first one is expected to become the true hostname of the instance, while all of them have to be added at least to /etc/hosts. In any case I agree it is something we should support.