---

- name: Stop swopdash lite
  raw: 'Stop-Process -processname Swopdash*'

- block:

  - name: Clean package path
    win_file:
      state: absent
      path: "{{ remote_package_folder }}\\"

  - name: Create package directory
    win_file:
      path: "{{ remote_package_folder }}"
      state: directory

  - name: Download Swopdash Lite package
    local_action: shell {{ driving_root }}/scripts/tools/s3_sync_lib.py {{swopdash_lite_s3_url}} {{ local_path }}/
    run_once: true

  - name: Download Swopdash Lite prereqs
    local_action: shell {{ driving_root }}/scripts/tools/s3_sync_lib.py {{prereqs_s3_url}} {{ local_path }}/
    run_once: true

  - name: Copy Swopdash package to Swopdash Lite
    win_copy:
      src: "{{ local_path }}/{{ swopdash_lite_s3_url | basename }}"
      dest: "{{ remote_package_folder }}\\"

  - name: Extract Swopdash package
    win_unzip:
      src: "{{ remote_package_folder }}\\{{ swopdash_lite_s3_url | basename }}"
      dest: "{{ remote_package_folder }}"

  - name: Copy Prereqs package to Swopdash Lite
    win_copy:
      src: "{{ local_path }}/{{ prereqs_s3_url | basename }}"
      dest: "{{ remote_package_folder }}\\"

  - name: Install Prereqs
    win_command: "{{ remote_package_folder }}\\{{ prereqs_s3_url | basename }} /passive"

  - name: Enable Robot Name API
    win_environment:
      state: "present"
      name: "ZOOX_ROBOT_NAME"
      value: "{{ robot_name }}"
      level: "machine"

  when: swopdash_lite_deploy_mode == "deploy"

- name: Launch Swopdash Lite
  script: files/start.ps1 "{{ remote_package_folder }}\\{{ swopdash_lite_s3_url | basename }}" "{{ ansible_user }}" "{{ ansible_password }}"
  when: swopdash_lite_deploy_mode == "start" or swopdash_lite_deploy_mode == "deploy"
  ignore_errors: yes
