# Disk setup for an ingest kiosk

- block:
    - name: install required packages for disk usage
      # required packages for:
      #   - Create logical volume
      #   - Mounting from the hot-swap bays
      apt:
        name: "{{ item }}"
        state: present
        update_cache: yes
        cache_valid_time: 3600
        install_recommends: no
      with_items:
        - "exfat-fuse"
        - "exfat-utils"
        - "lvm2"
      tags:
        - kiosk_host
        - kiosk_disk

    - name: create logical volume group from the local cache disks
      lvg:
        vg: jbod
        pvs: "{{ LOCAL_CACHE_DISKS }}"
      tags:
        - kiosk_host
        - kiosk_disk
      ignore_errors: yes

    - name: create local cache volume from the above logical volume group
      lvol:
        vg: jbod
        lv: logcache
        size: "100%VG"
        state: present
      tags:
        - kiosk_host
        - kiosk_disk

    - name: create local cache filesystem
      filesystem:
        dev: /dev/mapper/jbod-logcache
        fstype: ext4
      tags:
        - kiosk_host
        - kiosk_disk

    - name: mount local cache filesystem to the known mount point
      mount:
        state: mounted
        fstype: ext4
        src: /dev/mapper/jbod-logcache
        name: "{{LOCAL_CACHE_MOUNT}}"
        opts: rw
      tags:
        - kiosk_host
        - kiosk_disk

    - name: make local cache directory on local cache filesystem
      file:
        path: "{{LOCAL_CACHE_DIR}}"
        group: "{{LOCAL_CACHE_GROUP}}"
        owner: "{{INGEST_USER}}"
        state: directory
        mode: 'u+rwx,g+rx,o+rx'
      tags:
        - kiosk_host
        - kiosk_disk

    - name: make local cache staging directory under local cache directory
      file:
        path: "{{LOCAL_CACHE_DIR}}/.stage"
        group: "{{LOCAL_CACHE_GROUP}}"
        owner: "{{INGEST_USER}}"
        state: directory
        mode: 'u+rwx,g+rx,o+rx'
      tags:
        - kiosk_host
        - kiosk_disk

    - name: make local cache quarantine directory under local cache directory
      file:
        path: "{{LOCAL_CACHE_DIR}}/.quarantine"
        group: "{{LOCAL_CACHE_GROUP}}"
        owner: "{{INGEST_USER}}"
        state: directory
        mode: 'u+rwx,g+rx,o+rx'
      tags:
        - kiosk_host
        - kiosk_disk

  become: yes
