Comment 0 for bug 1705306

Revision history for this message
Jon Gjengset (jonhoo) wrote :

cloud-init fails to set the hostname on Arch Linux with the following error:

[CLOUDINIT] util.py[DEBUG]: Failed to set the hostname to dev1.localdomain (dev1)
                                         Traceback (most recent call last):
                                           File "/usr/lib/python2.7/site-packages/cloudinit/config/cc_set_hostname.py", line 33, in handle
                                             cloud.distro.set_hostname(hostname, fqdn)
                                           File "/usr/lib/python2.7/site-packages/cloudinit/distros/__init__.py", line 96, in set_hostname
                                             self._write_hostname(writeable_hostname, self.hostname_conf_fn)
                                           File "/usr/lib/python2.7/site-packages/cloudinit/distros/arch.py", line 132, in _write_hostname
                                             util.write_file(out_fn, conf, 0o644)
                                           File "/usr/lib/python2.7/site-packages/cloudinit/util.py", line 1662, in write_file
                                             content = encode_text(content)
                                           File "/usr/lib/python2.7/site-packages/cloudinit/util.py", line 97, in encode_text
                                             return text.encode(encoding)
                                         AttributeError: 'HostnameConf' object has no attribute 'encode'

The bug is that _write_hostname passes conf instead of str(conf) to util.write_file (compare distros/arch.py#n122 and distros/debian.py#n112).