From bc468187f59b7f30b3fe5438207dfecb7b18f8ca Mon Sep 17 00:00:00 2001 From: Martin Jackson Date: Sun, 8 Dec 2024 18:55:42 -0600 Subject: [PATCH] Always become user we are managing --- tasks/get_systemd_units_info.yml | 5 ++--- tasks/main.yml | 4 ++-- tasks/manage_units.yml | 4 ++-- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/tasks/get_systemd_units_info.yml b/tasks/get_systemd_units_info.yml index 8705957..888af24 100644 --- a/tasks/get_systemd_units_info.yml +++ b/tasks/get_systemd_units_info.yml @@ -8,8 +8,7 @@ systemd_units: user: "{{ __systemd_units_info.key }}" user_facts: "{{ ansible_facts['systemd_units_user'] | d({}) }}" - become: "{{ __systemd_units_info.key != 'root' }}" - become_user: "{{ __systemd_units_info.key if __systemd_units_info.key != 'root' - else omit }}" + become: true + become_user: "{{ __systemd_units_info.key }}" environment: XDG_RUNTIME_DIR: "{{ __systemd_units_info.value['xdg_dir'] }}" diff --git a/tasks/main.yml b/tasks/main.yml index 448a0b4..5a7ce0f 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -114,8 +114,8 @@ daemon_reload: true scope: "{{ 'system' if item == 'root' else 'user' }}" loop: "{{ __users_with_changes }}" - become: "{{ item != 'root' }}" - become_user: "{{ item if item != 'root' else omit }}" + become: true + become_user: "{{ item }}" environment: XDG_RUNTIME_DIR: "{{ __systemd_user_info[item]['xdg_dir'] }}" vars: diff --git a/tasks/manage_units.yml b/tasks/manage_units.yml index b1b3280..a626bcb 100644 --- a/tasks/manage_units.yml +++ b/tasks/manage_units.yml @@ -33,7 +33,7 @@ masked: "{{ __systemd_masked | bool if __systemd_masked | length > 0 else omit }}" scope: "{{ 'system' if item.user == 'root' else 'user' }}" loop: "{{ __systemd_dict_list }}" - become: "{{ item.user != 'root' }}" - become_user: "{{ item.user if item.user != 'root' else omit }}" + become: true + become_user: "{{ item.user }}" environment: XDG_RUNTIME_DIR: "{{ item.xdg_dir }}"