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

103 lines
3.0 KiB
YAML

---
- name: "samba : install samba"
ansible.builtin.apt:
name:
- "samba"
- "samba-client"
- name: "samba : configure \"music-rip\" 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_rip_config
- name: "samba : configure \"music-dvd\" samba share"
ansible.builtin.blockinfile:
path: "/etc/samba/smb.conf"
mode: 0644
insertafter: "EOF"
marker: "# {mark} ANSIBLE MANAGED BLOCK MUSIC:DVD"
block: |
[music-dvd]
comment = DVD drive
path = {{ music_user_home_directory }}/dvd
browseable = yes
read only = no
guest ok = no
create mask = 0644
directory mask = 0755
register: music_rip_samba_dvd_config
- name: "samba : configure \"music-collection\" samba share"
ansible.builtin.blockinfile:
path: "/etc/samba/smb.conf"
mode: 0644
insertafter: "EOF"
marker: "# {mark} ANSIBLE MANAGED BLOCK MUSIC:COLLECTION"
block: |
[music-collection]
comment = Music archive
path = {{ music_user_data_collection_directory }}
browseable = yes
read only = yes
register: music_rip_samba_collection_config
- name: "samba : configure \"music-archive\" samba share"
ansible.builtin.blockinfile:
path: "/etc/samba/smb.conf"
mode: 0644
insertafter: "EOF"
marker: "# {mark} ANSIBLE MANAGED BLOCK MUSIC:ARCHIVE"
block: |
[music-archive]
comment = Music archive
path = {{ music_user_data_archive_directory }}
browseable = yes
read only = yes
register: music_rip_samba_archive_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_rip_config.changed or
music_rip_samba_dvd_config.changed or
music_rip_samba_collection_config.changed or
music_rip_samba_archive_config.changed) and
not music_rip_samba_start.changed