From b87c60c41e66408e7858088c7857d0b9fb48da03 Mon Sep 17 00:00:00 2001 From: Christoph Date: Wed, 29 Jul 2026 23:32:24 +0200 Subject: [PATCH] fix(samba-remove-user.yml): enhance command structure and error handling for samba user removal tasks --- roles/common/tasks/samba-remove-user.yml | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/roles/common/tasks/samba-remove-user.yml b/roles/common/tasks/samba-remove-user.yml index 98a0c1f..eb0d05b 100644 --- a/roles/common/tasks/samba-remove-user.yml +++ b/roles/common/tasks/samba-remove-user.yml @@ -3,10 +3,14 @@ # - Remove unwanted users # --- - name: "(samba-remove-user.yml) Check if samba user exists for removable system user" - ansible.builtin.shell: pdbedit -w -L | awk -F":" '{ print $1 }' | grep -q '{{ item.name }}' - register: samba_remove_system_users_present - changed_when: "samba_remove_system_users_present.rc == 0" - failed_when: "samba_remove_system_users_present.rc > 1" + ansible.builtin.shell: + executable: /bin/bash + cmd: | + set -o pipefail + pdbedit -w -L | awk -F":" '{ print $1 }' | grep -q '{{ item.name }}' + register: common_samba_remove_system_users_present + changed_when: "common_samba_remove_system_users_present.rc == 0" + failed_when: "common_samba_remove_system_users_present.rc > 1" with_items: - "{{ remove_samba_users }}" loop_control: @@ -15,15 +19,19 @@ - system-user - samba-user -- name: (samba-remove-user.yml) Remove (old) system users from samba - ansible.builtin.shell: > - smbpasswd -s -x {{ item.item.name }} +- name: (samba-remove-user.yml) Remove (old) system users from samba # noqa no-handler + ansible.builtin.shell: + executable: /bin/bash + cmd: | + set -o pipefail + smbpasswd -s -x {{ item.item.name }} with_items: - - "{{ samba_remove_system_users_present.results }}" + - "{{ common_samba_remove_system_users_present.results }}" loop_control: label: "{{ item.item.name }}" when: - item.changed + changed_when: true tags: - system-user - samba-user