From ca74d003bafc8827f483d2c0c32982dd3e133ae8 Mon Sep 17 00:00:00 2001 From: Mike Holloway Date: Fri, 20 Sep 2024 03:47:35 -0400 Subject: [PATCH] Improve su with bash function --- tasks/main.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tasks/main.yml b/tasks/main.yml index e79851a..f2e7979 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -26,8 +26,8 @@ - name: Create machinectl bash alias lineinfile: path: "/home/{{ item }}/.bashrc" - regexp: '^alias su=' - line: "alias su=\"machinectl shell --uid\"" + regexp: '^su() ' + line: "su() { if [[ $1 == "-" ]]; then command machinectl shell --uid "$2"; else command machinectl shell --uid "$1"; fi; }" loop: "{{ service_users }}" - lineinfile: