Red Hat Bugzilla – Bug 1417025
cloud-init tries to run hostnamectl before dbus is up
Last modified: 2017-11-20 10:34:16 EST
Description of problem: === From bug 1393094#c9 === I found an issue with the new cloud-init - basically during the run of cloud-init it tries to set the hostname using hostnamectl but dbus hasn't started yet and it fails. We need to figure this out. from the debug log: ``` 2017-01-25 08:59:38,338 - util.py[DEBUG]: Running module set_hostname (<module 'cloudinit.config.cc_set_hostname' from '/usr/lib/python3.5/site-packages/cloudinit/config/cc_set_hostname.py'>) failed Traceback (most recent call last): File "/usr/lib/python3.5/site-packages/cloudinit/stages.py", line 776, in _run_modules freq=freq) File "/usr/lib/python3.5/site-packages/cloudinit/cloud.py", line 54, in run return self._runners.run(name, functor, args, freq, clear_on_fail) File "/usr/lib/python3.5/site-packages/cloudinit/helpers.py", line 187, in run results = functor(*args) File "/usr/lib/python3.5/site-packages/cloudinit/config/cc_set_hostname.py", line 47, in handle cloud.distro.set_hostname(hostname, fqdn) File "/usr/lib/python3.5/site-packages/cloudinit/distros/__init__.py", line 84, in set_hostname self._write_hostname(writeable_hostname, self.hostname_conf_fn) File "/usr/lib/python3.5/site-packages/cloudinit/distros/rhel.py", line 130, in _write_hostname util.subp(['hostnamectl', 'set-hostname', str(hostname)]) File "/usr/lib/python3.5/site-packages/cloudinit/util.py", line 1850, in subp cmd=args) cloudinit.util.ProcessExecutionError: Unexpected error while running command. Command: ['hostnamectl', 'set-hostname', 'cloudhost.localdomain'] Exit code: 1 Reason: - Stdout: - Stderr: Failed to create bus connection: No such file or directory ``` and from the journal you can see that dbus starts after cloud-init: ``` -bash-4.3# journalctl -u cloud-init | grep -P 'Starting|hostname' Jan 25 08:59:36 localhost.localdomain systemd[1]: Starting Initial cloud-init job (metadata service crawler)... Jan 25 08:59:38 localhost.localdomain cloud-init[1308]: 2017-01-25 08:59:38,331 - util.py[WARNING]: Failed to set the hostname to cloudhost.localdomain (cloudhost) Jan 25 08:59:38 localhost.localdomain cloud-init[1308]: 2017-01-25 08:59:38,338 - util.py[WARNING]: Running module set_hostname (<module 'cloudinit.config.cc_set_hostname' from '/usr/lib/python3.5/site-packages/cloudinit/config/cc_set_hostname.py'>) failed -bash-4.3# -bash-4.3# -bash-4.3# journalctl -u dbus | head -n 2 -- Logs begin at Wed 2017-01-25 08:59:29 UTC, end at Wed 2017-01-25 09:02:04 UTC. -- Jan 25 08:59:38 localhost.localdomain systemd[1]: Started D-Bus System Message Bus. ``` We need to file a bug upstream and/or send a patch to get this fixed for us. I pulled the patch from the commit in the first comment of this BZ and applied it to cloud-init 0.7.8 in Fedora and built a scratch build: https://koji.fedoraproject.org/koji/taskinfo?taskID=17405006 Version-Release number of selected component (if applicable): cloud-init-0.7.9-1.fc26
I added a potential fix to cloud-init-0.7.9-2.fc26 by removing DefaultDependencies=no from cloud-init.service. Note that there is still discussion on this issue occurring upstream.
This bug appears to have been reported against 'rawhide' during the Fedora 26 development cycle. Changing version to '26'.
I'm still running into this on cloud-init-0.7.9-9.fc27.noarch: [root@localhost log]# rpm -qv cloud-init cloud-init-0.7.9-9.fc27.noarch from /var/log/cloud-init.log [...] 2017-11-14 16:34:34,265 - util.py[DEBUG]: Running module set_hostname (<module 'cloudinit.conf ig.cc_set_hostname' from '/usr/lib/python3.6/site-packages/cloudinit/config/cc_set_hostname.py '>) failed Traceback (most recent call last): File "/usr/lib/python3.6/site-packages/cloudinit/stages.py", line 776, in _run_modules freq=freq) File "/usr/lib/python3.6/site-packages/cloudinit/cloud.py", line 54, in run return self._runners.run(name, functor, args, freq, clear_on_fail) File "/usr/lib/python3.6/site-packages/cloudinit/helpers.py", line 187, in run results = functor(*args) File "/usr/lib/python3.6/site-packages/cloudinit/config/cc_set_hostname.py", line 47, in han dle cloud.distro.set_hostname(hostname, fqdn) File "/usr/lib/python3.6/site-packages/cloudinit/distros/__init__.py", line 84, in set_hostn ame self._write_hostname(writeable_hostname, self.hostname_conf_fn) File "/usr/lib/python3.6/site-packages/cloudinit/distros/rhel.py", line 130, in _write_hostn ame util.subp(['hostnamectl', 'set-hostname', str(hostname)]) File "/usr/lib/python3.6/site-packages/cloudinit/util.py", line 1850, in subp cmd=args) cloudinit.util.ProcessExecutionError: Unexpected error while running command. Command: ['hostnamectl', 'set-hostname', 'test2.home.wawak.org'] Exit code: 1 Reason: - Stdout: - Stderr: Failed to create bus connection: No such file or directory
I'm seeing the same issue with ovirt nodes running CentOS 7. The cloud-init logs show a bus connection error as shown below. 2017-11-20 10:20:54,076 - cc_set_hostname.py[DEBUG]: Setting the hostname to test.example.com (test) 2017-11-20 10:20:54,076 - util.py[DEBUG]: Running command ['hostnamectl', 'set-hostname', 'test.example.com'] with allowed return codes [0] (shell=False, capture=True) 2017-11-20 10:20:54,109 - util.py[WARNING]: Failed to set the hostname to test.example.com (test) 2017-11-20 10:20:54,109 - util.py[DEBUG]: Failed to set the hostname to test.example.com (test) 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/rhel.py", line 130, in _write_hostname util.subp(['hostnamectl', 'set-hostname', str(hostname)]) File "/usr/lib/python2.7/site-packages/cloudinit/util.py", line 1858, in subp cmd=args) ProcessExecutionError: Unexpected error while running command. Command: ['hostnamectl', 'set-hostname', 'test.example.com'] Exit code: 1 Reason: - Stdout: - Stderr: Failed to create bus connection: No such file or directory