Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 34 additions & 25 deletions tasks/install-apt.yml
Original file line number Diff line number Diff line change
@@ -1,42 +1,51 @@
# code: language=ansible
---
- name: Remove from old package installation (apt list)
become: true
vars:
old_apt_source_file: '/etc/apt/sources.list.d/vscode.list'

block:
- name: Check if old source file exists
ansible.builtin.stat:
path: "{{ old_apt_source_file }}"
register: old_source_file_stat

- name: Remove old source file
ansible.builtin.file:
path: "{{ old_apt_source_file }}"
state: absent
when: old_source_file_stat.stat.exists

- name: Remove old apt key file (only if old source file existed)
ansible.builtin.file:
path: '/etc/apt/keyrings/microsoft.asc'
state: absent
when: old_source_file_stat.stat.exists

- name: Install dependencies (apt)
become: true
ansible.builtin.apt:
name:
- ca-certificates
- apt-transport-https
- python3-debian
state: present

- name: Create APT keyrings dir
become: true
ansible.builtin.file:
path: '/etc/apt/keyrings'
state: directory
mode: 'u=rwx,go=rx'

- name: Install key (apt)
become: true
ansible.builtin.get_url:
url: '{{ visual_studio_code_mirror }}/keys/microsoft.asc'
dest: '/etc/apt/keyrings/'
mode: 'u=rw,go=r'
force: true

- name: Install VS Code repo (apt)
become: true
ansible.builtin.apt_repository:
repo: >-
deb [arch={{ visual_studio_code_deb_architecture }}
{{ visual_studio_code_gpgcheck | ternary("", " trusted=true") }}
signed-by=/etc/apt/keyrings/microsoft.asc]
{{ visual_studio_code_mirror }}/repos/code stable main
filename: vscode
state: present
ansible.builtin.deb822_repository:
name: vscode
types: deb
uris: "{{ visual_studio_code_mirror }}/repos/code"
suites: stable
components: main
architectures: "{{ visual_studio_code_deb_architecture }}"
signed_by: "{{ visual_studio_code_mirror + '/keys/microsoft.asc' if visual_studio_code_gpgcheck else omit }}"
trusted: "{{ true if not visual_studio_code_gpgcheck else omit }}"
when: not visual_studio_code_skip_add_repo

- name: Install VS Code (apt)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We also need update cache to have access to code

Suggested change
- name: Install VS Code (apt)
- name: Install VS Code (apt)
become: true
ansible.builtin.apt:
name: "{{ visual_studio_code_package }}{{ (visual_studio_code_version | length > 0) | ternary('=' + visual_studio_code_version, '') }}"
state: present
update_cache: true

become: true
ansible.builtin.apt:
name: "{{ visual_studio_code_package }}{{ (visual_studio_code_version | length > 0) | ternary('=' + visual_studio_code_version, '') }}"
state: present
update_cache: true