#####################################
### someone's ansible provisioner ###
#####################################
# Part of: https://git.somenet.org/root/pub/somesible.git
# 2017-2026 by someone <someone@somenet.org>
#
---
- name: make sure /btrfs exists
  file:
    path: "/btrfs"
    state: directory
    mode: 0711
    owner: "root"
    group: "root"
  when: setup_btrfs_helpers | bool


- name: copy btrfs-snapshot.sh
  copy:
    src: "{{item}}"
    dest: "/btrfs/btrfs-snapshot.sh"
    mode: 0700
    owner: "root"
    group: "root"
  with_first_found:
    - "{{lookup('env','PWD')}}/host_files/{{inventory_hostname}}/{{role_name}}/btrfs-snapshot.sh"
    - "{{lookup('env','PWD')}}/group_files/{{group_files_group}}/{{role_name}}/btrfs-snapshot.sh"
    - "{{lookup('env','PWD')}}/group_files/all/{{role_name}}/btrfs-snapshot.sh"
    - "default/btrfs-snapshot.sh"
  when: setup_btrfs_helpers | bool


- name: copy btrfs-regen-snaphot-homelinks.sh
  copy:
    src: "{{item}}"
    dest: "/btrfs/btrfs-regen-snaphot-homelinks.sh"
    mode: 0700
    owner: "root"
    group: "root"
  with_first_found:
    - "{{lookup('env','PWD')}}/host_files/{{inventory_hostname}}/{{role_name}}/btrfs-regen-snaphot-homelinks.sh"
    - "{{lookup('env','PWD')}}/group_files/{{group_files_group}}/{{role_name}}/btrfs-regen-snaphot-homelinks.sh"
    - "{{lookup('env','PWD')}}/group_files/all/{{role_name}}/btrfs-regen-snaphot-homelinks.sh"
    - "default/btrfs-regen-snaphot-homelinks.sh"
  when: setup_btrfs_helpers | bool


- name: setup cron.d file for btrfs snapshots + scrub.
  template:
    src: "{{item}}"
    dest: "/etc/cron.d/btrfs"
    mode: 0644
    owner: "root"
    group: "root"
  with_first_found:
    - "{{lookup('env','PWD')}}/host_files/{{inventory_hostname}}/{{role_name}}/cron.j2"
    - "{{lookup('env','PWD')}}/group_files/{{group_files_group}}/{{role_name}}/cron.j2"
    - "{{lookup('env','PWD')}}/group_files/all/{{role_name}}/cron.j2"
    - "templates/cron.j2"
  when: setup_btrfs_helpers | bool
