summaryrefslogtreecommitdiff
path: root/roles/storage/zfs/volume/tasks/main.yml
blob: 6ad861e18f0ab4ca05262ef0504dba78a8385068 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
---
- name: compute full zfs volume path
  set_fact:
    zfs_volume_path_full: "{{ ('parent' in zfs_volume) | ternary((zfs_volume.parent.pool | default(''))~'/'~(zfs_volume.parent.name | default('')), zfs_volume.pool) }}/{{ zfs_volume.name }}"

- name: create zfs dataset
  zfs:
    name: "{{ zfs_volume_path_full }}"
    extra_zfs_properties: "{{ zfs_volume.properties | dehumanize_zfs_properties | default(omit) }}"
    state: present

- name: gather volume mountpoint info
  zfs_facts:
    name: "{{ zfs_volume_path_full }}"
    properties: mountpoint
  register: zfs_volume_info

- name: export volume mountpoint
  set_fact:
    storage_volume_mountpoint: "{{ zfs_volume_info.ansible_facts.ansible_zfs_datasets[0].mountpoint }}"

- name: bind mount volume
  when:
  - "'dest' in zfs_volume"
  - zfs_volume.dest != storage_volume_mountpoint
  block:
  - name: create bind mount
    mount:
      src: "{{ zfs_volume_info.ansible_facts.ansible_zfs_datasets[0].mountpoint }}"
      path: "{{ zfs_volume.dest }}"
      fstype: none
      opts: "bind,x-systemd.automount,nofail{% if zfs_volume.mntopts is defined %},{{ zfs_volume.mntopts }}{% endif %}"
      state: mounted

  - name: update volume mountpoint
    set_fact:
      storage_volume_mountpoint: "{{ zfs_volume.dest }}"

- name: set volume owner/group and mode
  file:
    state: directory
    path: "{{ storage_volume_mountpoint }}"
    mode: "{{ zfs_volume.mode | default(omit) }}"
    owner: "{{ zfs_volume.owner | default(omit) }}"
    group: "{{ zfs_volume.group | default(omit) }}"