5

When I try to set hostname with an ansible module, I get

TASK [set hostname] **************************************************************************************
fatal: [10.1.38.15]: FAILED! => {"changed": false, "msg": "Command failed rc=1, out=, err=Failed to create bus connection: No such file or directory\n"}

Interestingly when I ssh to the computer and I try to set hostname with hostnamectl I also get an error.

bash-4.2# hostnamectl set-hostname foo.bar.com
Failed to create bus connection: No such file or directory

I believe these two issues are related, but dbus shows that it's running,

● dbus.service - D-Bus System Message Bus
   Loaded: loaded (/usr/lib/systemd/system/dbus.service; static; vendor preset: disabled)
   Active: active (running) since Tue 2020-01-07 09:04:45 CST; 2h 28min ago

What could the problem be? I am using Centos 7.

Apparently, when I strace hostnamectl I get

connect(3, {sa_family=AF_LOCAL, sun_path="/var/run/dbus/system_bus_socket"}, 33) = -1 ENOENT (No such file or directory)

And I can confirm that /var/run/dbus/system_bus_socket is not present

The ansible play is

- name: set hostname
  hostname
    name: cp-1-2.foo.bar.com
1
  • 2
    Did you try to restart dbus? Jan 7, 2020 at 18:04

2 Answers 2

6

I can confirm that /var/run/dbus/system_bus_socket is not present.

There is your problem right there, then. /var/run should symbolically link to /run, and /run/dbus/system_bus_socket was created as a consequence of dbus.socket.

No amount of fiddling with dbus.service will fix either of those if they are not the case, by the way. Fix the symbolic link, or re-initialize the socket.

2
  • 3
    "re-initialize the socket": This can be done using systemctl start dbus.socket. Mar 23, 2021 at 5:18
  • thank you, that did it!
    – imbr
    Apr 18, 2023 at 23:05
1

your symbolic link to /var/run is broken. recreate the symbolic link and you should be good to go.

sudo rm /var/run -R
sudo ln -s /run /var
sudo reboot
1

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .