Cannot set hostname on Arch Linux

Bug #1705306 reported by Jon Gjengset
8
This bug affects 1 person
Affects Status Importance Assigned to Milestone
cloud-init
Fix Released
Medium
Unassigned

Bug Description

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).

Related branches

Jon Gjengset (jonhoo)
description: updated
Revision history for this message
Jon Gjengset (jonhoo) wrote :
Revision history for this message
Joshua Powers (powersj) wrote :

Hi Jon! Thanks for taking the time to file this bug.

I tried to reproduce this using a lxc of arch and was unable to. Can you give me 1) the version of cloud-init you are using, 2) your cloud-config, 3) as well as your cloud-init log? Below is what I tried:

$ lxc launch images:archlinux arch
$ lxc exec arch bash
$ pacman -S cloud-init
# updated 05_logging.cfg per https://bugs.archlinux.org/task/53036
# - [ *log_base, *log_file ]
with
- [ *log_base ]
# And my user-data:
#cloud-config
hostname: foobar
$ cloud-init --file user-data single --name=set_hostname --frequency=always
$ hostname
foobar

Changed in cloud-init:
status: New → Incomplete
Revision history for this message
Jon Gjengset (jonhoo) wrote :
Download full text (4.2 KiB)

After doing some more digging, you also need to set

system_info:
   distro: arch

in /etc/cloud/cloud.cfg, as Arch includes the upstream cloud.cfg which has ubuntu set as the distro (which uses str(conf) and thus doesn't have the issue).

I'm using the NoCloud provider with

$ cat meta-data
instance-id: iid-local01
local-hostname: arch-cloud

and nothing interesting in user-data. The execution log on the server looks like this.

$ sudo pacman -Qi cloud-init | grep Version
Version : 0.7.9-1
$ sudo cloud-init single --name=set_hostname --frequency=always
Cloud-init v. 0.7.9 running 'single' at Fri, 21 Jul 2017 17:08:18 +0000. Up 433.04 seconds.
2017-07-21 17:08:18,193 - util.py[DEBUG]: Cloud-init v. 0.7.9 running 'single' at Fri, 21 Jul 2017 17:08:18 +0000. Up 433.04 seconds.
2017-07-21 17:08:18,194 - stages.py[DEBUG]: Using distro class <class 'cloudinit.distros.arch.Distro'>
2017-07-21 17:08:18,194 - stages.py[DEBUG]: Running module set_hostname (<module 'cloudinit.config.cc_set_hostname' from '/usr/lib/python2.7/site-packages/cloudinit/config/cc_set_hostname.pyc'>) with frequency always
2017-07-21 17:08:18,194 - helpers.py[DEBUG]: Running config-set_hostname using lock (<cloudinit.helpers.DummyLock object at 0x7fe51cf5d690>)
2017-07-21 17:08:18,194 - cc_set_hostname.py[DEBUG]: Setting the hostname to arch-cloud.localdomain (arch-cloud)
2017-07-21 17:08:18,195 - util.py[DEBUG]: Reading from /etc/hostname (quiet=False)
2017-07-21 17:08:18,195 - util.py[WARNING]: Failed to set the hostname to arch-cloud.localdomain (arch-cloud)
2017-07-21 17:08:18,197 - util.py[DEBUG]: Failed to set the hostname to arch-cloud.localdomain (arch-cloud)
Traceback (most recent call last):
  File "/usr/lib/python2.7/site-packages/cloudinit/config/cc_set_hostname.py", line 47, in handle
    cloud.distro.set_hostname(hostname, fqdn)
  File "/usr/lib/python2.7/site-packages/cloudinit/distros/__init__.py", line 84, in set_hostname
    self._write_hostname(writeable_hostname, self.hostname_conf_fn)
  File "/usr/lib/python2.7/site-packages/cloudinit/distros/arch.py", line 120, in _write_hostname
    util.write_file(out_fn, conf, 0o644)
  File "/usr/lib/python2.7/site-packages/cloudinit/util.py", line 1747, in write_file
    content = encode_text(content)
  File "/usr/lib/python2.7/site-packages/cloudinit/util.py", line 154, in encode_text
    return text.encode(encoding)
AttributeError: 'HostnameConf' object has no attribute 'encode'
2017-07-21 17:08:18,198 - util.py[WARNING]: Running module set_hostname (<module 'cloudinit.config.cc_set_hostname' from '/usr/lib/python2.7/site-packages/cloudinit/config/cc_set_hostname.pyc'>) failed
2017-07-21 17:08:18,199 - util.py[DEBUG]: Running module set_hostname (<module 'cloudinit.config.cc_set_hostname' from '/usr/lib/python2.7/site-packages/cloudinit/config/cc_set_hostname.pyc'>) failed
Traceback (most recent call last):
  File "/usr/lib/python2.7/site-packages/cloudinit/stages.py", line 776, in _run_modules
    freq=freq)
  File "/usr/lib/python2.7/site-packages/cloudinit/cloud.py", line 54, in run
    return self._runners.run(name, functor, args, freq, clear_on_fail)
  File "/usr/lib/python2.7/site-packages/cloudinit/he...

Read more...

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

As a side-note, I have filed a bug with Arch to make them change "system_info.distro" in the bundled config: https://bugs.archlinux.org/task/54898

Revision history for this message
Joshua Powers (powersj) wrote :

Thanks for the updates Jon, really appreciate it!

Changed in cloud-init:
status: Incomplete → Confirmed
Revision history for this message
Jon Gjengset (jonhoo) wrote :

Happy to help! Let me know if there's anything else I can do.
Oh, and while I have you here — could you also take a look at https://bugs.launchpad.net/cloud-init/+bug/1663045 ?

Scott Moser (smoser)
Changed in cloud-init:
importance: Undecided → Medium
Joshua Powers (powersj)
Changed in cloud-init:
status: Confirmed → Fix Committed
Revision history for this message
Scott Moser (smoser) wrote : Fixed in Cloud-init 17.1

This bug is believed to be fixed in cloud-init in 17.1. If this is still a problem for you, please make a comment and set the state back to New

Thank you.

Changed in cloud-init:
status: Fix Committed → Fix Released
Revision history for this message
James Falcon (falcojr) wrote :
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.