---
- hosts: all
  name: update weka kernel driver
  serial: 1
  become: yes
  vars:
    driver_filename: weka-driver-1.0.0-6c0781e9b594272d55051736dc41773c.squashfs
    driver_sha: 4c0d23d28dac244b760f2fce367a2a3f531c07e1ee349467428fe509c6ce7fa9
  tasks:
  - name: stop Kraken
    docker_compose:
      project_src: /etc/docker-compose/kraken-worker
      state: absent
    failed_when: false
    tags: stop-kraken

  - name: umount weka
    systemd:
      name: mnt-weka.mount
      state: stopped
    tags: umount-weka

  - name: delete current driver
    file:
      path: /opt/weka/data/weka_driver
      state: absent
    tags: remove-driver

  - name: umount squashfs
    mount:
      path: /opt/weka/packages/{{ driver_filename }}
      state: unmounted
    tags: remove-driver

  - name: delete squashfs
    file:
      path: /opt/weka/dist/image/{{ driver_filename }}
      state: absent
    tags: remove-driver

  - name: download new squashfs
    get_url:
      url: https://z3.zooxlabs.com/zoox-third-party/{{ driver_sha }}/{{ driver_filename }}
      dest: /opt/weka/dist/image/{{ driver_filename }}
      checksum: sha256:{{ driver_sha }}
    tags: update-driver

  - name: mount weka
    systemd:
      name: mnt-weka.mount
      state: started
    tags: restore

  # we need to start docker because we made docker start after weka,
  # and we umounted weka earlier, which would stop docker
  - name: start docker
    systemd:
      name: docker.service
      state: started
    tags: restore

  - name: start kraken
    docker_compose:
      project_src: /etc/docker-compose/kraken-worker
      state: present
    tags: restore
