This commit is contained in:
Kris Lamoureux 2023-05-04 03:09:34 -04:00
parent 9142254a57
commit ba44547066
2 changed files with 44 additions and 0 deletions

View File

@ -0,0 +1,25 @@
- name: Install Samba
ansible.builtin.apt:
name: samba
state: present
- name: Create Samba users
ansible.builtin.command: "smbpasswd -a -s {{ item.name }}"
args:
stdin: "{{ item.password }}\n{{ item.password }}"
loop: "{{ samba.users }}"
register: samba_users
changed_when: "'User added' in samba_users.stdout"
- name: Ensure share directories exist
ansible.builtin.file:
path: "{{ item.path }}"
state: directory
mode: 0755
loop: "{{ samba.shares }}"
- name: Configure Samba shares
ansible.builtin.template:
src: smb.conf.j2
dest: /etc/samba/smb.conf
notify: samba_restart

View File

@ -0,0 +1,19 @@
[global]
workgroup = WORKGROUP
server string = Samba Server %v
netbios name = {{ ansible_hostname }}
security = user
map to guest = bad user
dns proxy = no
{% for user in samba.users %}
smb encrypt = {{ 'mandatory' if user.encrypt | default(false) else 'disabled' }}
{% endfor %}
{% for share in samba.shares %}
[{{ share.name }}]
path = {{ share.path }}
browsable = yes
guest ok = no
read only = {{ 'yes' if share.read_only | default(false) else 'no' }}
valid users = {{ share.valid_users }}
{% endfor %}