2023-06-07 06:12:17 +00:00
|
|
|
- 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 }}"
|
2023-06-07 06:12:17 +00:00
|
|
|
args:
|
|
|
|
stdin: "{{ item.password }}\n{{ item.password }}"
|
|
|
|
loop: "{{ samba.users }}"
|
2023-10-21 01:30:25 +00:00
|
|
|
loop_control:
|
|
|
|
label: "{{ item.name }}"
|
2023-06-07 06:12:17 +00:00
|
|
|
register: samba_users
|
2023-10-21 01:30:25 +00:00
|
|
|
changed_when: "'Added user' in samba_users.stdout"
|
2023-06-07 06:12:17 +00:00
|
|
|
|
|
|
|
- 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"
|
2023-06-07 06:12:17 +00:00
|
|
|
loop: "{{ samba.shares }}"
|
|
|
|
|
|
|
|
- name: Configure Samba shares
|
|
|
|
ansible.builtin.template:
|
|
|
|
src: smb.conf.j2
|
|
|
|
dest: /etc/samba/smb.conf
|
2024-09-11 02:35:20 +00:00
|
|
|
mode: "644"
|
2023-06-07 06:12:17 +00:00
|
|
|
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 }}"
|
2023-06-10 02:26:47 +00:00
|
|
|
when: manage_firewall
|