我正在尝试使用cloud-init脚本设置我的Bluemix VM的主机名,但它引发了错误:
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
登录服务器,我可以看到/var/lib/cloud/data/previous-hostname
不存在:
[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
/usr/lib/python2.7/site-packages/cloudinit/config/cc_set_hostname.py
中的代码看起来非常简单:
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
可能导致此错误的原因是什么?是否可以提供我自己的cc_set_hostname.py脚本版本,我可以添加其他调试来转储Exception
?