fix(samba-user.yml): improve command structure and enhance error handling for samba user management
This commit is contained in:
@@ -35,13 +35,16 @@
|
||||
# Samba users mut be also system users
|
||||
#
|
||||
- name: (samba_user.yml) Add (system) users if not yet exists..
|
||||
ansible.builtin.command: "/root/bin/admin-stuff/add_new_user.sh {{ item.name }} '{{ item.password }}'"
|
||||
ansible.builtin.command:
|
||||
cmd: "/root/bin/admin-stuff/add_new_user.sh {{ item.name }} '{{ item.password }}'"
|
||||
creates: "/home/{{ item.name }}"
|
||||
loop: "{{ samba_user }}"
|
||||
loop_control:
|
||||
label: "{{ item.name }}"
|
||||
when:
|
||||
- ansible_facts.getent_passwd is defined
|
||||
- item.name not in ansible_facts.getent_passwd
|
||||
changed_when: true
|
||||
tags:
|
||||
- samba-server
|
||||
- samba-user
|
||||
@@ -66,10 +69,14 @@
|
||||
- system-user
|
||||
|
||||
- name: (samba-user.yml) Check if samba user exists
|
||||
ansible.builtin.shell: pdbedit -w -L | awk -F":" '{ print $1 }' | grep -e "^{{ item.name }}"
|
||||
register: samba_user_present
|
||||
changed_when: "samba_user_present.rc == 1"
|
||||
failed_when: "samba_user_present.rc > 1"
|
||||
ansible.builtin.shell:
|
||||
executable: /bin/bash
|
||||
cmd: |
|
||||
set -o pipefail
|
||||
pdbedit -w -L | awk -F":" '{ print $1 }' | grep -e "^{{ item.name }}"
|
||||
register: common_samba_user_present
|
||||
changed_when: "common_samba_user_present.rc == 1"
|
||||
failed_when: "common_samba_user_present.rc > 1"
|
||||
loop: "{{ samba_user }}"
|
||||
loop_control:
|
||||
label: "{{ item.name }}"
|
||||
@@ -77,13 +84,17 @@
|
||||
- samba-server
|
||||
- samba-user
|
||||
|
||||
- name: (samba-user.yml) Add user to samba (with system users password)
|
||||
ansible.builtin.shell: >
|
||||
- name: (samba-user.yml) Add user to samba (with system users password) # noqa no-handler
|
||||
ansible.builtin.shell:
|
||||
executable: /bin/bash
|
||||
cmd: |
|
||||
set -o pipefail
|
||||
(echo '{{ item.item.password }}'; echo '{{ item.item.password }}') | smbpasswd -s -a {{ item.item.name }}
|
||||
loop: "{{ samba_user_present.results }}"
|
||||
loop: "{{ common_samba_user_present.results }}"
|
||||
when: item.changed
|
||||
loop_control:
|
||||
label: "{{ item.item.name }}"
|
||||
changed_when: true
|
||||
tags:
|
||||
- samba-server
|
||||
- samba-user
|
||||
@@ -94,7 +105,7 @@
|
||||
- name: (samba_user.yml) Check if folder '/data/backup' exists using file module
|
||||
ansible.builtin.stat:
|
||||
path: /data/backup
|
||||
register: data_backup_dir
|
||||
register: common_data_backup_dir
|
||||
when:
|
||||
- inventory_hostname == 'zapata.opp.netz'
|
||||
tags:
|
||||
@@ -114,7 +125,7 @@
|
||||
label: "{{ item.name }}"
|
||||
when:
|
||||
- inventory_hostname == 'zapata.opp.netz'
|
||||
- data_backup_dir.stat.isdir is defined and data_backup_dir.stat.isdir
|
||||
- common_data_backup_dir.stat.isdir is defined and common_data_backup_dir.stat.isdir
|
||||
tags:
|
||||
- samba-server
|
||||
- samba-user
|
||||
|
||||
Reference in New Issue
Block a user