cloud-config.service is failing with a unicodedecodeerror

Bug #1646966 reported by Lars Kellogg-Stedman
This bug affects 1 person
Affects Status Importance Assigned to Milestone

Bug Description

With 0.7.8 on a CentOS 7 environment, I am seeing cloud-init fail (when called from cloud-config.service) with the following traceback:

  Traceback (most recent call last):
    File "/usr/lib/python2.7/site-packages/cloudinit/", line 785, in _run_modules
    File "/usr/lib/python2.7/site-packages/cloudinit/", line 70, in run
      return, functor, args, freq, clear_on_fail)
    File "/usr/lib/python2.7/site-packages/cloudinit/", line 199, in run
      results = functor(*args)
    File "/usr/lib/python2.7/site-packages/cloudinit/config/", line 37, in handle
      cloud.distro.apply_locale(locale, locale_cfgfile)
    File "/usr/lib/python2.7/site-packages/cloudinit/distros/", line 135, in apply_locale
      rhel_util.update_sysconfig_file(out_fn, locale_cfg)
    File "/usr/lib/python2.7/site-packages/cloudinit/distros/", line 37, in update_sysconfig_file
      (exists, contents) = read_sysconfig_file(fn)
    File "/usr/lib/python2.7/site-packages/cloudinit/distros/", line 64, in read_sysconfig_file
      return (exists, SysConf(contents))
    File "/usr/lib/python2.7/site-packages/cloudinit/distros/parsers/", line 61, in __init__
    File "/usr/lib/python2.7/site-packages/", line 1242, in __init__
      self._load(infile, configspec)
    File "/usr/lib/python2.7/site-packages/", line 1302, in _load
      infile = self._handle_bom(infile)
    File "/usr/lib/python2.7/site-packages/", line 1457, in _handle_bom
      if not line.startswith(BOM):
  UnicodeDecodeError: 'ascii' codec can't decode byte 0xff in position 0: ordinal not in range(128)

This looks like it is ultimately a bug with the 'configobj' module (CentOS 7 has 4.7.2). The following reproduces the failure:

  import configobj
  import cloudinit.util

  contents = cloudinit.util.load_file('/etc/locale.conf').splitlines()
  cfg = configobj.ConfigObj(contents, interpolation=False, write_empty_values=True)

This only happens when 'contents' is a unicode string. If we call .encode() on the string first, everything works correctly:

  import configobj
  import cloudinit.util

  contents = cloudinit.util.load_file('/etc/locale.conf').encode('utf-8').splitlines()
  cfg = configobj.ConfigObj(contents, interpolation=False, write_empty_values=True)

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

Hi! Thanks for taking the time for filing a bug.

There has been significant work on the CentOS/RHEL support in the newest version of cloud-init. If you are willing and able, it would be great if you could try the latest version from our COPR repo:

Changed in cloud-init:
status: New → Incomplete
Revision history for this message
Launchpad Janitor (janitor) wrote :

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

Changed in cloud-init:
status: Incomplete → Expired
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.