Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

systemd_service - Add the machine parameter (#82958) #82959

Open
wants to merge 1 commit into
base: devel
Choose a base branch
from

Conversation

jimmy-lt
Copy link

@jimmy-lt jimmy-lt commented Apr 2, 2024

Fixes #82958

systemctl's --machine option execute the operation in the context of a local user session or a local container.

This provides a failsafe way to run systemd on behalf of another user than setting the XDG_RUNTIME_DIR variable.

SUMMARY

When trying to run systemd as another user, the following is advised:

- name: Run a user service when XDG_RUNTIME_DIR is not set on remote login
  ansible.builtin.systemd_service:
    name: myservice
    state: started
    scope: user
  environment:
    XDG_RUNTIME_DIR: "/run/user/{{ myuid }}"

However, this may not always work and can fail in various ways, typically:

Failed to connect to bus: Operation not permitted

Since systemd 248, the --machine option is available to to open a connection to the session bus of a specific user.

ISSUE TYPE
  • Feature Pull Request
ADDITIONAL INFORMATION
- name: Run from within a specific user session
  ansible.builtin.systemd_service:
    name: myservice
    state: started
    scope: user
    machine: myuser@.host
"invocation": {
    "module_args": {
        "daemon_reexec": false,
        "daemon_reload": false,
        "enabled": true,
        "force": null,
        "machine": "myuser@.host",
        "masked": null,
        "name": "myservice",
        "no_block": false,
        "scope": "user",
        "state": "started"
    }
}

@ansibot ansibot added feature This issue/PR relates to a feature request. needs_triage Needs a first human triage before being processed. module This issue/PR relates to a module. has_issue ci_verified Changes made in this PR are causing tests to fail. needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. labels Apr 2, 2024
@ansibot
Copy link
Contributor

ansibot commented Apr 2, 2024

The test ansible-test sanity --test pep8 [explain] failed with 1 error:

lib/ansible/modules/systemd_service.py:88:161: E501: line too long (177 > 160 characters)

click here for bot help

systemctl's `--machine` option execute the operation in the context of a local
user session or a local container.

This provides a failsafe way to run systemd on behalf of another user than
setting the `XDG_RUNTIME_DIR` variable.

Signed-off-by: Jimmy Thrasibule <dev@jimmy.lt>
@jimmy-lt jimmy-lt force-pushed the feature/#82958-systemd_service-machine-parameter branch from 8ceea6f to ec6688e Compare April 2, 2024 20:55
@ansibot ansibot removed needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. ci_verified Changes made in this PR are causing tests to fail. labels Apr 2, 2024
@nitzmahone nitzmahone removed the needs_triage Needs a first human triage before being processed. label Apr 4, 2024
@ansibot ansibot added the stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. label Apr 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature This issue/PR relates to a feature request. has_issue module This issue/PR relates to a module. stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

systemd_service: Support for the "machine" parameter
3 participants