Skip to content

Failed systemd service task under root: Failed to connect to bus: Operation not permitted #125

Open
@petRUShka

Description

@petRUShka

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions