Skip to content

Commit 8278310

Browse files
committed
Fix conflict with apt installation
When vscode is updated via apt upgrade, it automatically creates a new apt source file in /etc/apt/sources.list.d/vscode.sources using the new apt format. This file then used the dearmor key in /usr/share/keyrings which conflict with the armored key specified in the /etc/apt/sources.list.d/vscode.list file that was created by ansible. To avoid this conflict, I used the new apt format like mentioned in the vscode installation documentation: https://code.visualstudio.com/docs/setup/linux#_install-vs-code-on-linux Also removed conflicting files.
1 parent c5bb4fa commit 8278310

File tree

1 file changed

+48
-11
lines changed

1 file changed

+48
-11
lines changed

tasks/install-apt.yml

Lines changed: 48 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,33 +6,70 @@
66
name:
77
- ca-certificates
88
- apt-transport-https
9+
- gpg
910
state: present
1011

12+
- name: Remove old key (apt)
13+
become: true
14+
ansible.builtin.file:
15+
path: '/etc/apt/keyrings/microsoft.asc'
16+
state: absent
17+
1118
- name: Create APT keyrings dir
1219
become: true
1320
ansible.builtin.file:
14-
path: '/etc/apt/keyrings'
21+
path: '/usr/share/keyrings/'
1522
state: directory
1623
mode: 'u=rwx,go=rx'
1724

18-
- name: Install key (apt)
25+
- name: Download key (apt)
1926
become: true
2027
ansible.builtin.get_url:
2128
url: '{{ visual_studio_code_mirror }}/keys/microsoft.asc'
22-
dest: '/etc/apt/keyrings/'
29+
dest: '/tmp/'
30+
mode: 'u=rw,go=r'
31+
force: true
32+
33+
- name: Dearmor key (apt)
34+
ansible.builtin.command: gpg --dearmor -o /tmp/microsoft.gpg /tmp/microsoft.asc
35+
args:
36+
creates: '/tmp/microsoft.gpg'
37+
38+
- name: Install key (apt)
39+
become: true
40+
ansible.builtin.copy:
41+
src: '/tmp/microsoft.gpg'
42+
dest: '/usr/share/keyrings/microsoft.gpg'
2343
mode: 'u=rw,go=r'
2444
force: true
2545

46+
- name: Clean up temporary key files (apt)
47+
ansible.builtin.file:
48+
path: "{{ item }}"
49+
state: absent
50+
loop:
51+
- /tmp/microsoft.asc
52+
- /tmp/microsoft.gpg
53+
54+
- name: Remove old repo (apt)
55+
become: true
56+
ansible.builtin.file:
57+
path: '/etc/apt/sources.list.d/vscode.list'
58+
state: absent
59+
when: not visual_studio_code_skip_add_repo
60+
2661
- name: Install VS Code repo (apt)
2762
become: true
28-
ansible.builtin.apt_repository:
29-
repo: >-
30-
deb [arch={{ visual_studio_code_deb_architecture }}
31-
{{ visual_studio_code_gpgcheck | ternary("", " trusted=true") }}
32-
signed-by=/etc/apt/keyrings/microsoft.asc]
33-
{{ visual_studio_code_mirror }}/repos/code stable main
34-
filename: vscode
35-
state: present
63+
ansible.builtin.copy:
64+
content: |
65+
Types: deb
66+
URIs: {{ visual_studio_code_mirror }}/repos/code
67+
Suites: stable
68+
Components: main
69+
Architectures: {{ visual_studio_code_deb_architecture }}
70+
{{ 'Trusted: yes' if not visual_studio_code_gpgcheck else 'Signed-By: /usr/share/keyrings/microsoft.gpg' }}
71+
dest: '/etc/apt/sources.list.d/vscode.sources'
72+
mode: 'u=rw,go=r'
3673
when: not visual_studio_code_skip_add_repo
3774

3875
- name: Install VS Code (apt)

0 commit comments

Comments
 (0)