summaryrefslogtreecommitdiff
path: root/roles/storage/zfs/volume/tasks/main.yml
blob: 0dc0e82d6fa8ec0dc978e30cd0272bf0952feb68 (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
---
  ## TODO: implement recursive nesting
- name: check volume parent
  when: "'parent' in zfs_volume"
  assert:
    msg: "the volume parent must be of type zfs and must not have a parent"
    that:
    - zfs_volume.parent.type == 'zfs'
    - "'parent' not in zfs_volume.parent"

- name: create zfs dataset
  zfs:
    name: "{{ ('parent' in zfs_volume) | ternary((zfs_volume.parent.pool | default(''))~'/'~(zfs_volume.parent.name | default('')), zfs_volume.pool) }}/{{ zfs_volume.name }}"
    extra_zfs_properties: "{{ zfs_volume.properties | dehumanize_zfs_properties | default(omit) }}"
    state: present

- name: compute derivated mountpoint
  set_fact:
    zfs_volume_mountpoint: "{{ (zfs_pools[zfs_volume.parent.pool | default(zfs_volume.pool)].mountpoint, ('parent' in zfs_volume) | ternary((zfs_volume.parent.name | default('')), ''), zfs_volume.name) | path_join }}"

- name: bind mount filesystem
  when:
  - "'dest' in zfs_volume"
  - zfs_volume.dest != zfs_volume_mountpoint
  mount:
    src: "{{ zfs_volume_mountpoint }}"
    path: "{{ zfs_volume.dest }}"
    fstype: none
    opts: bind,x-systemd.automount,nofail
    state: mounted

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