Score:0

Ansible - No such file error when activating systemctl Podman user socket

mx flag
hpy

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!

Score:0
mv flag

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.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.