homelab/roles/base/tasks/samba.yml

47 lines
1.0 KiB
YAML
Raw Permalink Normal View History

- name: Install Samba
ansible.builtin.apt:
name: samba
state: present
- name: Create Samba users
2023-10-21 01:30:25 +00:00
ansible.builtin.command: "smbpasswd -a {{ item.name }}"
args:
stdin: "{{ item.password }}\n{{ item.password }}"
loop: "{{ samba.users }}"
2023-10-21 01:30:25 +00:00
loop_control:
label: "{{ item.name }}"
register: samba_users
2023-10-21 01:30:25 +00:00
changed_when: "'Added user' in samba_users.stdout"
- name: Ensure share directories exist
ansible.builtin.file:
path: "{{ item.path }}"
owner: "{{ item.owner }}"
group: "{{ item.group }}"
state: directory
2023-10-21 01:30:25 +00:00
mode: "755"
loop: "{{ samba.shares }}"
- name: Configure Samba shares
ansible.builtin.template:
src: smb.conf.j2
dest: /etc/samba/smb.conf
2023-10-21 01:30:25 +00:00
mode: "700"
notify: restart_samba
- name: Start smbd and enable on boot
ansible.builtin.service:
name: smbd
state: started
enabled: true
- name: Allow SMB connections
community.general.ufw:
rule: allow
port: 445
proto: tcp
from: "{{ item }}"
state: enabled
loop: "{{ samba.firewall }}"
when: manage_firewall