4

I'm trying to set my Bluemix VM's hostname with a cloud-init script, but it's throwing an error:

cloud-init[1143]: Cloud-init v. 0.7.5 running 'init' at Sun, 27 Sep 2015 13:14:39 +0000. Up 66.82 seconds.
cloud-init[1143]: ci-info: +++++++++++++++++++++++Net device info+++++++++++++++++++++++
cloud-init[1143]: ci-info: +--------+------+-----------+-----------+-------------------+
cloud-init[1143]: ci-info: | Device |  Up  |  Address  |    Mask   |     Hw-Address    |
cloud-init[1143]: ci-info: +--------+------+-----------+-----------+-------------------+
cloud-init[1143]: ci-info: |  lo:   | True | 127.0.0.1 | 255.0.0.0 |         .         |
cloud-init[1143]: ci-info: | eth0:  | True |     .     |     .     | fa:16:3e:20:97:7b |
cloud-init[1143]: ci-info: +--------+------+-----------+-----------+-------------------+
cloud-init[1143]: ci-info: !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!Route info failed!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

CentOS Linux 7 (Core)
Kernel 3.10.0-123.13.2.el7.x86_64 on an x86_64

localhost login: cloud-init[1143]: 2015-09-27 13:15:07,239 - util.py[WARNING]: Failed to set the hostname to XXXXXXXXX (XXXX)
cloud-init[1143]: 2015-09-27 13:15:07,258 - util.py[WARNING]: Running set_hostname (<module 'cloudinit.config.cc_set_hostname' from '/usr/lib/python2.7/site-packages/cloudinit/config/cc_set_hostname.pyc'>) failed
cloud-init[1143]: 2015-09-27 13:15:32,287 - util.py[WARNING]: Failed to write hostname XXXXXXXXX to /var/lib/cloud/data/previous-hostname

Logging into the server, I can see that /var/lib/cloud/data/previous-hostname doesn't exist:

[ibmcloud@host-192-168-0-30 ~]$ ls -lh /var/lib/cloud/data/previous-hostname
ls: cannot access /var/lib/cloud/data/previous-hostname: No such file or directory

The code in /usr/lib/python2.7/site-packages/cloudinit/config/cc_set_hostname.py looks pretty simple:

from cloudinit import util


def handle(name, cfg, cloud, log, _args):
    if util.get_cfg_option_bool(cfg, "preserve_hostname", False):
        log.debug(("Configuration option 'preserve_hostname' is set,"
                    " not setting the hostname in module %s"), name)
        return

    (hostname, fqdn) = util.get_hostname_fqdn(cfg, cloud)
    try:
        log.debug("Setting the hostname to %s (%s)", fqdn, hostname)
        cloud.distro.set_hostname(hostname, fqdn)
    except Exception:
        util.logexc(log, "Failed to set the hostname to %s (%s)", fqdn,
                    hostname)
        raise

What could be causing this error? Is it possible to provide my own version of the cc_set_hostname.py script that I can add additional debugging to dump the Exception?

Chris Snow
  • 23,813
  • 35
  • 144
  • 309
  • Did you find a solution to this ? I am facing a similar issue: http://stackoverflow.com/questions/44059479/cloud-init-fails-on-util-pywarning-failed-to-disable-password-for-user-cento There are quite a few cloud-init issue users are facing which remains unanswered. – askb May 20 '17 at 01:42
  • I am also stuck with similar issue : https://stackoverflow.com/questions/46253755/not-able-change-the-hostname-with-cloud-init-script – Naveen Kerati Sep 16 '17 at 12:11
  • me too actually! :) – Lethargos Feb 01 '22 at 18:38

0 Answers0