---
- name: Set up slack
  hosts: localhost
  vars:
    uid: "{{ lookup('env','USER') }}"
    slack_version: "{{ lookup('ansible.builtin.pipe','../scripts/get_slack_version.sh') }}"
  connection: local
  become: false
  tasks:
    - name: Have slack allready installed
      stat:
        path: /usr/bin/slack
      register: have_slack
    - name: Install slack package
      become: true
      ansible.builtin.apt:
        deb: https://downloads.slack-edge.com/releases/linux/{{ slack_version }}/prod/x64/slack-desktop-{{ slack_version }}-amd64.deb 
      when: not have_slack.stat.exists
    - name: set up local desktop dir
      ansible.builtin.file:
        dest: /home/{{ uid }}/.local/share/applications
        state: directory
    - name: set up better desktop file
      ansible.builtin.template:
        src: ../templates/slack.desktop.j2
        dest: /home/{{ uid }}/.local/share/applications/slack.desktop
        owner: '{{ uid }}'
        group: '{{ uid }}'
        mode: '0644'
