Failed systemd service task under root: Failed to connect to bus: Operation not permitted
petRUShka opened this issue · 1 comments
petRUShka commented
The [gnupg : Enable gpg-agent.socket]
task works well under sudo ansible-playbook -i localhost playbook.yml
and fails if I run it under su
(e.g. as root)
TASK [gnupg : Enable gpg-agent.socket] ***************************************************************************************************************************************
fatal: [localhost]: FAILED! => {"changed": false, "cmd": "/usr/bin/systemctl --user", "msg": "Failed to connect to bus: Operation not permitted", "rc": 1, "stderr": "Failed t
o connect to bus: Operation not permitted\n", "stderr_lines": ["Failed to connect to bus: Operation not permitted"], "stdout": "", "stdout_lines": []}
Task code is:
- name: Enable gpg-agent.socket
systemd:
name: gpg-agent.socket
scope: user
enabled: yes
state: started
become: yes
become_user: "{{ user.name }}"
environment:
XDG_RUNTIME_DIR: "/run/user/{{ user.uid }}"
when: gnupg.enable_agent == True
pigmonkey commented
Try changing the scope from user
to global
in the task (and the other user socket tasks in that file). That may work.