blob: 80950dcb80be4c5eeaf886de747a5bf465cda7ef (
plain) (
tree)
|
|
- name: Install Samba
apt:
name:
- samba
- smbclient
- cifs-utils
update_cache: true
- name: Disable Samba NetBIOS server nmbd
systemd:
name: nmbd
state: stopped
enabled: false
- name: render samba config file
template:
src: smb.conf.j2
dest: "/etc/samba/smb.conf"
mode: 0644
# https://stackoverflow.com/questions/44762488/non-interactive-samba-user-creation-via-ansible
- name: shell - create samba users
shell: >
set -e -o pipefail
&& (pdbedit --user={{ item.username }} 2>&1 > /dev/null)
|| (echo '{{ item.password }}'; echo '{{ item.password }}')
| smbpasswd -s -a {{ item.username }}
args:
executable: /bin/bash
register: samba_create_users
changed_when: "'Added user' in samba_create_users.stdout"
loop: "{{ samba_users }}"
no_log: true
- name: shell - set samba passwords correctly
shell: >
set -e -o pipefail
&& (smbclient -U {{ item.username }}%{{ item.password }} -L 127.0.0.1 2>&1 > /dev/null)
|| (echo '{{ item.password }}'; echo '{{ item.password }}')
| smbpasswd {{ item.username }}
args:
executable: /bin/bash
register: samba_verify_users
changed_when: "'New SMB password' in samba_verify_users.stdout"
loop: "{{ samba_users }}"
no_log: true
- name: Restart SMB service
systemd:
name: smbd
state: restarted
enabled: true
daemon_reload: true
|