--- # --- # - Remove unwanted users # --- - name: (samba_user.yml) Check if samba user exists for removable nis user shell: pdbedit -w -L | awk -F":" '{ print $1 }' | grep '{{ item.name }}' register: samba_deleted_user_present changed_when: "samba_deleted_user_present.rc == 0" failed_when: "samba_deleted_user_present.rc > 1" with_items: - "{{ nis_deleted_user }}" loop_control: label: '{{ item.name }}' tags: - samba-user - name: (samba_user.yml) Remove (old) users from samba shell: "smbpasswd -s -x {{ item.name }}" with_items: - "{{ nis_deleted_user }}" loop_control: label: '{{ item.name }}' when: samba_deleted_user_present is changed tags: - samba-user # --- # - default user/groups # --- - name: (samba_user.yml) Check if samba user exists for nis user shell: pdbedit -w -L | awk -F":" '{ print $1 }' | grep '{{ item.name }}' register: samba_nis_user_present changed_when: "samba_nis_user_present.rc > 0" failed_when: "samba_nis_user_present.rc > 1" with_items: - "{{ nis_user }}" loop_control: label: '{{ item.name }}' when: - item.is_samba_user is defined and item.is_samba_user|bool tags: - samba-user - name: (samba_user.yml) Add nis user to samba (with nis users password) shell: "echo -e '{{ item.password }}\n{{ item.password }}\n' | smbpasswd -s -a {{ item.name }}" loop: "{{ nis_user }}" loop_control: label: '{{ item.name }}' when: - item.is_samba_user is defined and item.is_samba_user|bool - samba_nis_user_present is changed notify: Renew nis databases tags: - samba-user