ansible-playbooks/roles/zfs/tasks/dataset-ownership.yml
2025-11-14 00:05:58 +01:00

25 lines
990 B
YAML

---
# due to Ansible limitations, we cannot loop over a block, so we loop over distinct task files
# @see https://stackoverflow.com/a/58911694
- name: Set ownership on dataset mountpoint
block:
- name: Get the mountpoint
ansible.builtin.command: "zfs get -H -o value mountpoint {{ dataset.name }}"
register: mountpoint
changed_when: false
- name: Fail if mountpoint is system directory
ansible.builtin.fail:
msg: "Mountpoint resolved to a system directory ({{ mountpoint.stdout }}), aborting to avoid changing ownership."
when:
- mountpoint.stdout | trim == ''
- mountpoint.stdout | trim is not match('^/$|^(/usr|/bin|/sbin|/etc|/var|/lib|/lib64)$')
- name: Set mountpoint ownership
ansible.builtin.file:
path: "{{ mountpoint.stdout }}"
owner: "{{ dataset.user | default(ansible_user) }}"
group: "{{ dataset.group | default(ansible_user) }}"
state: directory
recurse: false