Docker and systemd, getting rid of dreaded 'Failed to connect to bus' error
The following error has been the bane of my existence for the past few months:
TASK [geerlingguy.containerd : Ensure containerd is started and enabled at boot.] ***
fatal: [instance]: FAILED! => {
"changed": false,
"cmd": "/bin/systemctl",
"msg": "Failed to connect to bus: No such file or directory",
"rc": 1,
"stderr": "Failed to connect to bus: No such file or directory",
"stderr_lines": [
"Failed to connect to bus: No such file or directory"
],
"stdout": "",
"stdout_lines": []
}
Since I use Molecule with my Ansible roles and playbooks to test them in identical CI environments both locally and in GitHub Actions, I can maintain an identical environment inside which tests are run. And many of my roles and playbooks need to test whether systemd services are configured and run correctly.
But Docker recently switched from cgroups v1 to cgroups v2, and that started this 'Failed to connect to bus' business—systemd relied on some configuration that was easy enough to add in the past: just run your containers with these options: