39 lines
1.2 KiB
YAML
39 lines
1.2 KiB
YAML
|
---
|
||
|
- block:
|
||
|
- name: Install requirements
|
||
|
package:
|
||
|
name: "{{ item }}"
|
||
|
state: present
|
||
|
loop: "{{ smb_packages }}"
|
||
|
|
||
|
- name: Ensure credentials folder exist
|
||
|
file:
|
||
|
path: /root/.smbcredentials
|
||
|
owner: root
|
||
|
group: root
|
||
|
mode: 0600
|
||
|
state: directory
|
||
|
|
||
|
- name: Create secrets file
|
||
|
template:
|
||
|
src: "smbcredentials.j2"
|
||
|
dest: "/root/.smbcredentials/{{ item.name }}"
|
||
|
mode: 0600
|
||
|
loop: "{{ smb_shares }}"
|
||
|
loop_control:
|
||
|
label: "/root/.smbcredentials/{{ item.name }}"
|
||
|
when: item.password is defined and item.password
|
||
|
|
||
|
- name: Mount volume
|
||
|
mount:
|
||
|
path: "{{ item.mountpoint }}"
|
||
|
src: "{{ item.source }}"
|
||
|
fstype: "cifs"
|
||
|
opts: "{{ ((item.mountopts | default([])) if not (item.password is defined and item.password) else ((item.mountopts | default([])) + ['credentials=/root/.smbcredentials/' + item.name])) | join(',') }}"
|
||
|
state: "{{ item.state | default('mounted') }}"
|
||
|
loop: "{{ smb_shares }}"
|
||
|
loop_control:
|
||
|
label: "mount: {{ item.source }} {{ item.mountpoint }} cifs {% if item.mountopts is defined %}{{ item.mountopts | join(',') }}{% endif %}"
|
||
|
become: True
|
||
|
become_user: root
|