Skip to content

Conversation

@ltshb
Copy link

@ltshb ltshb commented Aug 4, 2025

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.

This should solve #263

@CLAassistant
Copy link

CLAassistant commented Aug 4, 2025

CLA assistant check
All committers have signed the CLA.

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.
@ltshb ltshb force-pushed the bug-apt-install-gpg branch from 8612197 to 8278310 Compare August 4, 2025 07:45
@ltshb
Copy link
Author

ltshb commented Aug 4, 2025

Hi @freemanjp I think I can solve the issue #263 could you have a look at this PR ? Thanks

@huyz
Copy link

huyz commented Aug 18, 2025

It would be great to have this merged.

@MaKaNu
Copy link

MaKaNu commented Sep 11, 2025

As an alternative, an implementation via https://docs.ansible.com/ansible/latest/collections/ansible/builtin/deb822_repository_module.html might also help and could reduce boilerplate

mode: 'u=rw,go=r'
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

@ltshb ltshb force-pushed the bug-apt-install-gpg branch from f8e2919 to c6f8a95 Compare September 15, 2025 15:20
Copy link
Author

@ltshb ltshb left a comment

Choose a reason for hiding this comment

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

@MaKaNu Thanks for the review, I've adapted the PR accordingly, hopefully this PR can get soon merged.

Copy link

@MaKaNu MaKaNu left a comment

Choose a reason for hiding this comment

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

#260 Is a similar PR, and we might need to discuss, which of them should be the preferred method.

I prefer the "include-task" pattern which #260 uses, but migration seems not handled yet.

Comment on lines 10 to 21
- name: Remove old key (apt)
become: true
ansible.builtin.file:
path: '/etc/apt/keyrings'
state: directory
mode: 'u=rwx,go=rx'
path: '/etc/apt/keyrings/microsoft.asc'
state: absent

- name: Install key (apt)
- name: Remove old repo (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
ansible.builtin.file:
path: '/etc/apt/sources.list.d/vscode.list'
state: absent
when: not visual_studio_code_skip_add_repo
Copy link

Choose a reason for hiding this comment

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

I am still not 100% sure if this should be executed before ansible.builtin.apt task above. Since if this is causing an issue, the apt module above might fail.

Further, I don't know how deb822_repository is working behind, but it seems they utilize the /etc/apt/keyrings/microsoft.asc path. While it is causing issues with the old method, the deb822 format seems to handle it in a way it does not.

So if Remove old key (apt) will remove the key and Install VS Code repo (apt) installs it again, those tasks cause non-Idempotent execution.

Copy link
Author

Choose a reason for hiding this comment

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

@MaKaNu You are right the key will always be removed and re-installed, I changed it to have a migration task on top before the install dependencies and this tasks only remove the key when the old apt list file is present to avoid this non-idempotent execution.

@ltshb ltshb requested a review from MaKaNu October 14, 2025 05:11
Copy link

@MaKaNu MaKaNu left a comment

Choose a reason for hiding this comment

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

LGFM. @freemanjp as the only contributor from gantsign I found on this repo, could you take a look at this PR or inform somebody else?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants