ansible-edda/playbooks/roles/music/rip/tasks/include/samba.yml
2023-11-04 21:19:09 +01:00

124 lines
3.6 KiB
YAML

---
- name: "samba : install samba"
ansible.builtin.apt:
name:
- "samba"
- "samba-client"
- name: "samba : configure \"music-download\" samba share"
ansible.builtin.blockinfile:
path: "/etc/samba/smb.conf"
mode: 0644
insertafter: "EOF"
marker: "# {mark} ANSIBLE MANAGED BLOCK MUSIC:DOWNLOAD"
block: |
[music-download]
comment = Music drive
path = {{ music_user_home_directory }}/download
browseable = yes
read only = no
guest ok = no
create mask = 0644
directory mask = 0755
register: music_rip_samba_download_config
- 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: |
set -o pipefail
(echo '{{ music_user_samba_password }}'; echo '{{ music_user_samba_password }}') |
smbpasswd -a {{ music_user_name }}
args:
executable: "/usr/bin/bash"
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_download_config.changed or
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