---
- name: cron | Create BTRFS scrub monthly job
  copy:
    content: |
      #!/bin/sh
      exec /sbin/btrfs scrub start -B {{ item }}
    dest: /etc/periodic/monthly/scrub-btrfs-{{ item | regex_replace('/', '@') }}
    owner: root
    group: root
    mode: '755'
  # PERF: a shorter version but requires `py3-jmespath`: '{{ ansible_mounts | json_query("[?fstype == `btrfs`].mount") }}'
  loop: '{{ ansible_mounts | selectattr("fstype", "equalto", "btrfs") | map(attribute="mount") | list }}'

- name: cron | Create ZFS pool scrub monthly job
  copy:
    content: |
      #!/bin/sh
      exec /usr/sbin/zpool scrub -w {{ item }}
    dest: /etc/periodic/monthly/scrub-zfs-{{ item }}
    mode: '755'
    owner: root
    group: root
  loop: '{{ ansible_zfs_pools | map(attribute="name") | list }}'
