---
# file: roles/postgres/tasks/zfs.yml

- name: "[ZFS bare metal] find the dataset for the postgres cluster at {{ pg_data_directory }}"
  shell: "grep \"$(df -h {{ pg_data_directory }} | awk '{ print $6 }' | grep /) \" /proc/mounts | awk '{ print $1 }'"
  register: zfs_dataset
  changed_when: false
  check_mode: no
  when: ansible_virtualization_role == "host" or ansible_virtualization_role == "NA" or ansible_virtualization_role is undefined
  tags:
    - postgres
    - zfs

- name: "[ZFS bare metal] logbias=throughput and recordsize = 8K on dataset {{ zfs_dataset.stdout }}"
  zfs:
    name: "{{ zfs_dataset.stdout }}"
    state: present
    extra_zfs_properties:
      logbias: throughput
      recordsize: 8192
  when: ansible_virtualization_role == "host" or ansible_virtualization_role == "NA" or ansible_virtualization_role is undefined
  tags:
    - postgres
    - zfs
