canonical / canonical/cloud-init

Cloudinit throws an error when the hostname is an integer

Open
#5,642 5 comments 0 reactions 0 assignees View on GitHub
bug incomplete
Dominant language
Python
Stars
3.8k
Forks
1.1k
Avg merge
2d 23h
Merged PRs (30d)
18

Description

# Bug report

When the hostname is an integer, cloud init fails in cloudinit/util.py line 1268:
```
if "hostname" in cfg and cfg["hostname"].find(".") > 0:
```

`cfg["hostname"]` has the hostname parsed as an integer, but it should be parsed as a string.

## Steps to reproduce the problem
1) Change your hostname to an integer, e.g. 12.
2) Reboot.

## Environment details
- Cloud-init version: `/usr/bin/cloud-init 24.1.3-0ubuntu1~22.04.5`
- Operating System Distribution: ubuntu 22.04

## cloud-init logs
```
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/cloudinit/cmd/main.py", line 786, in status_wrapper
ret = functor(name, args)
File "/usr/lib/python3/dist-packages/cloudinit/cmd/main.py", line 446, in main_init
_maybe_set_hostname(init, stage="local", retry_stage="network")
File "/usr/lib/python3/dist-packages/cloudinit/cmd/main.py", line 843, in _maybe_set_hostname
(hostname, _fqdn, _) = util.get_hostname_fqdn(
File "/usr/lib/python3/dist-packages/cloudinit/util.py", line 1240, in get_hostname_fqdn
if "hostname" in cfg and cfg["hostname"].find(".") > 0:
AttributeError: 'int' object has no attribute 'find'
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.