0

I am running an Ansible playbook on a fresh Oracle Linux 8 system. It includes a step where it asks systemctl to activate a user Podman socket like so:

- name: Enable podman socket
  vars: 
    userid: ansible_facts.getent_passwd.{{ ansible_user_id }}[1]
  ansible.builtin.systemd: 
    name: podman.socket
    enabled: yes
    state: started
    scope: user
  environment:
    XDG_RUNTIME_DIR: "/run/user/{{ userid }}"

This Ansible playbook is being run as the user (not root) to enable and start the user-level Podman socket.

However, running the playbook gave me this error:

fatal: [127.0.0.1]: FAILED! => {"changed": false, "cmd": "/bin/systemctl --user", "msg": "Failed to connect to bus: No such file or directory", "rc": 1, "stderr": "Failed to connect to bus: No such file or directory\n", "stderr_lines": ["Failed to connect to bus: No such file or directory"], "stdout": "", "stdout_lines": []}

If, instead of using Ansible, I manually run the following systemctl command, then the user Podman socket activates successfully:

systemctl --user enable podman.socket

What am I missing in my playbook and how do I fix it? Thanks!

Zeitounator
  • 1,199
  • 5
  • 12
hpy
  • 845
  • 3
  • 18
  • 28

1 Answers1

0

I ran into a similar issue, where I couldn't get the ansible module to enable and start podman.socket for the non-root user, but I could run the command (systemctl --user enable podman.socket) when using ssh to login as the user.

The error message I got was:

fatal: [x]: FAILED! => {"changed": false, "cmd": "/usr/bin/systemctl --user", "msg": "Failed to connect to bus: Operation not permitted", "rc": 1, "stderr": "Failed to connect to bus: Operation not permitted\n", "stderr_lines": ["Failed to connect to bus: Operation not permitted"], "stdout": "", "stdout_lines": []}

My solution was to use remote_user instead of become. I also added the DOCKER_HOST to the user's bashrc.

With the following two tasks I could enable and start podman.socket rootless.

- name: Export podman.socket
  become: '{{ user }}'
  become: true
  lineinfile: 
    dest: "/home/{{ user }}/.bashrc"
    line: "export DOCKER_HOST=unix:$XDG_RUNTIME_DIR/podman/podman.sock"
    insertafter: "EOF"

- name: Enable podman.socket for user
  remote_user: '{{ user }}'
  systemd: 
    name: "podman.socket"
    enabled: yes
    state: started
    scope: user

This was helpful in order to get docker-compose to work with podman and ansible.