- name: Configure sysctls
  sysctl:
    name: "{{ item.name }}"
    value: "{{ item.value }}"
    state: present
    sysctl_file: "/etc/sysctl.conf.local"
  loop:
    - name: net.link.ether.inet.proxyall
      value: "1"

- name: Install service configuration
  copy:
    src: "files/{{ item }}_rc.conf"
    dest: "/etc/rc.conf.d/{{ item }}"
    mode: 0644
    owner: root
    group: wheel
  loop:
    - nfsd
    - mountd
    - lockd
    - statd
    - rpcbind

- name: Create zfs datasets
  zfs:
    name: zdata/k8spersistent
    state: present
    extra_zfs_properties:
      sharenfs: "-network 10.215.1.0/24,-alldirs,-maproot=root:root"
      mountpoint: /k8spersistent

- name: Update ownership
  file:
    name: "{{ item }}"
    state: directory
    mode: 0777
    owner: root
    group: wheel
  loop:
    - /k8spersistent

- name: Install scripts
  copy:
    src: "files/{{ item.src }}"
    dest: "{{ item.dest }}"
    mode: 0755
    owner: root
    group: wheel
  loop:
    - src: k8s_snapshot.bash
      dest: /usr/local/bin/k8s_snapshot
    - src: k8s_rollback.bash
      dest: /usr/local/bin/k8s_rollback