---
- name: Deploy lesavka server binary
  hosts: lesavka_server
  become: true
  vars:
    lesavka_artifact_url: ""
    lesavka_artifact_dest: "/tmp/lesavka-server.tar.gz"
    lesavka_install_dir: "/usr/local/bin"
  tasks:
    - name: Ensure artifact URL is set
      assert:
        that:
          - lesavka_artifact_url | length > 0
        fail_msg: "Set lesavka_artifact_url to the Jenkins artifact tarball"

    - name: Download server artifact
      get_url:
        url: "{{ lesavka_artifact_url }}"
        dest: "{{ lesavka_artifact_dest }}"
        mode: "0644"

    - name: Unpack server artifact
      unarchive:
        src: "{{ lesavka_artifact_dest }}"
        dest: "{{ lesavka_install_dir }}"
        remote_src: true

    - name: Restart lesavka-server
      systemd:
        name: lesavka-server
        state: restarted
        daemon_reload: true
