[PATCH 07/12] linux-mirror: fix systemd scope for mirror-status when running as root

Daniel Gomez <[email protected]> Thu, 06 Nov 2025 23:36:01 +0100
Newsgroups dev.linux.lists.kdevops
Message-ID <[email protected]>
From: Daniel Gomez <[email protected]>

The mirror-status tasks were using hardcoded 'scope: user' when checking
systemd service and timer status. This fails when running as root with the
error "Failed to connect to user scope bus via local transport: No such
file or directory" because root doesn't have a user D-Bus session.

Use the dynamic systemd_scope variable instead, which is already set by the
"Set scope based on user" task. This variable correctly selects 'system'
scope when running as root and 'user' scope when running as a regular user,
ensuring the status checks work in both contexts.

Also fix the timer status label which had a typo with double dashes
(--mirror.timer instead of -mirror.timer).

Generated-by: Claude AI
Signed-off-by: Daniel Gomez <[email protected]>
---
 playbooks/roles/linux-mirror/tasks/main.yml | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/playbooks/roles/linux-mirror/tasks/main.yml b/playbooks/roles/linux-mirror/tasks/main.yml
index 0afd782a..74e980ff 100644
--- a/playbooks/roles/linux-mirror/tasks/main.yml
+++ b/playbooks/roles/linux-mirror/tasks/main.yml
@@ -167,7 +167,7 @@
 - name: Check systemd unit status for mirror services
   ansible.builtin.systemd_service:
     name: "{{ item.short_name | regex_replace('/', '-') }}-mirror.service"
-    scope: user
+    scope: "{{ systemd_scope }}"
   register: mirror_service_status
   with_items:
     - "{{ mirrors.get('mirrors') }}"
@@ -189,12 +189,12 @@
 - name: Check systemd unit status for mirror timers
   ansible.builtin.systemd_service:
     name: "{{ item.short_name | regex_replace('/', '-') }}-mirror.timer"
-    scope: user
+    scope: "{{ systemd_scope }}"
   register: mirror_timer_status
   with_items:
     - "{{ mirrors.get('mirrors') }}"
   loop_control:
-    label: "Checking service status for {{ item.short_name | regex_replace('/', '-') }}--mirror.timer ..."
+    label: "Checking timer status for {{ item.short_name | regex_replace('/', '-') }}-mirror.timer unit ..."
   tags: ["mirror-status"]
   when:
     - not install_only_git_daemon|bool

-- 
2.51.0