ansible-edda/playbooks/roles/music/rip/tasks/include/samba.yml

55 lines
1.5 KiB
YAML

---
- name: "samba : install samba"
ansible.builtin.apt:
name:
- "samba"
- "samba-client"
- name: "samba : configure samba share"
ansible.builtin.blockinfile:
path: "/etc/samba/smb.conf"
mode: 0644
insertafter: "EOF"
marker: "# {mark} ANSIBLE MANAGED BLOCK MUSIC:RIP"
block: |
[music-rip]
comment = Music drive
path = {{ music_user_home_directory }}/rip
browseable = yes
read only = no
guest ok = no
create mask = 0644
directory mask = 0755
register: music_rip_samba_config
- name: "samba : check for \"{{ music_user_name }}\" user"
ansible.builtin.shell: "pdbedit --user={{ music_user_name }} || /usr/bin/true"
changed_when: false
register: music_rip_samba_pdb_state
- name: "samba : add \"{{ music_user_name }}\" user"
ansible.builtin.shell: |
(echo '{{ music_user_samba_password }}'; echo '{{ music_user_samba_password }}') |
smbpasswd -a {{ music_user_name }}
when:
not music_rip_samba_pdb_state.stdout is match('^' ~ music_user_name ~ ':')
- name: "samba : enable samba"
ansible.builtin.systemd:
name: "smbd"
enabled: true
- name: "samba : start samba"
ansible.builtin.systemd:
name: "smbd"
state: "started"
register: music_rip_samba_start
- name: "samba : restart samba"
ansible.builtin.systemd:
name: "smbd"
state: "restarted"
when:
music_rip_samba_config.changed and
not music_rip_samba_start.changed