---

# Credits: Michael Heap

- name: Does the vscode apt file exist?
  become: yes
  command: test -f {{ apt_file }}
  register: vscode_apt_exists
  ignore_errors: True

- name: Add Microsoft key
  become: yes
  shell: wget -q -O - https://packages.microsoft.com/keys/microsoft.asc | apt-key add -
  when: vscode_apt_exists.rc == 1

- name: Add vscode repo
  become: yes
  copy: content="deb https://packages.microsoft.com/repos/vscode stable main" dest={{ apt_file }} owner=root group=root mode=644
  when: vscode_apt_exists.rc == 1

- name: Update apt cache
  become: yes
  apt: update_cache=yes
  when: vscode_apt_exists.rc == 1

- name: Install vscode
  become: yes
  apt:
    state: latest
    pkg: code
