xoxys.smb/tasks/main.yml

36 lines
1.1 KiB
YAML
Raw Normal View History

2020-01-25 23:09:27 +00:00
---
2024-02-19 09:37:58 +00:00
- name: Install requirements
ansible.builtin.package:
name: "{{ item }}"
state: present
loop: "{{ smb_packages }}"
- name: Ensure credentials folder exist
ansible.builtin.file:
path: /root/.smbcredentials
owner: root
group: root
mode: "0600"
state: directory
- name: Create secrets file
ansible.builtin.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
ansible.posix.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 %}"