From a077d65e5f7f415cc17abeee2264e24957ef97cd Mon Sep 17 00:00:00 2001 From: clarkzjw Date: Fri, 13 Jan 2023 16:53:03 -0800 Subject: change domain to clarkzjw.cc --- .../atlas/ansible/roles/samba/defaults/main.yaml | 3 ++ .../atlas/ansible/roles/samba/tasks/main.yaml | 53 ++++++++++++++++++++++ .../ansible/roles/samba/templates/smb.conf.j2 | 33 ++++++++++++++ 3 files changed, 89 insertions(+) create mode 100644 clarkzjw.cc/config/atlas/ansible/roles/samba/defaults/main.yaml create mode 100644 clarkzjw.cc/config/atlas/ansible/roles/samba/tasks/main.yaml create mode 100644 clarkzjw.cc/config/atlas/ansible/roles/samba/templates/smb.conf.j2 (limited to 'clarkzjw.cc/config/atlas/ansible/roles/samba') diff --git a/clarkzjw.cc/config/atlas/ansible/roles/samba/defaults/main.yaml b/clarkzjw.cc/config/atlas/ansible/roles/samba/defaults/main.yaml new file mode 100644 index 0000000..88c23b1 --- /dev/null +++ b/clarkzjw.cc/config/atlas/ansible/roles/samba/defaults/main.yaml @@ -0,0 +1,3 @@ +samba_users: +- username: clarkzjw + password: "{{ lookup('env', 'SAMBA_PASSWORD') }}" \ No newline at end of file diff --git a/clarkzjw.cc/config/atlas/ansible/roles/samba/tasks/main.yaml b/clarkzjw.cc/config/atlas/ansible/roles/samba/tasks/main.yaml new file mode 100644 index 0000000..80950dc --- /dev/null +++ b/clarkzjw.cc/config/atlas/ansible/roles/samba/tasks/main.yaml @@ -0,0 +1,53 @@ +- 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 diff --git a/clarkzjw.cc/config/atlas/ansible/roles/samba/templates/smb.conf.j2 b/clarkzjw.cc/config/atlas/ansible/roles/samba/templates/smb.conf.j2 new file mode 100644 index 0000000..06e2567 --- /dev/null +++ b/clarkzjw.cc/config/atlas/ansible/roles/samba/templates/smb.conf.j2 @@ -0,0 +1,33 @@ +[global] + workgroup = WORKGROUP + interfaces = 192.168.1.0/24 tailscale0 + bind interfaces only = yes + log file = /var/log/samba/log.%m + max log size = 1000 + logging = file + panic action = /usr/share/samba/panic-action %d + server role = standalone server + obey pam restrictions = yes + unix password sync = yes + passwd program = /usr/bin/passwd %u + passwd chat = *Enter\snew\s*\spassword:* %n\n *Retype\snew\s*\spassword:* %n\n *password\supdated\ssuccessfully* . + pam password change = yes + map to guest = bad user + +[homes] + comment = Home Directories + browseable = no + read only = yes + create mask = 0700 + directory mask = 0700 + valid users = %S + +[pool1] + comment = NAS Share + path = /pool1/clarkzjw + writable = yes + guest ok = no + valid users = @clarkzjw + force create mode = 770 + force directory mode = 770 + inherit permissions = yes -- cgit v1.2.3