Skip to content

Fix conflict with apt installation#264

Open
ltshb wants to merge 3 commits into
gantsign:masterfrom
ltshb:bug-apt-install-gpg
Open

Fix conflict with apt installation#264
ltshb wants to merge 3 commits into
gantsign:masterfrom
ltshb:bug-apt-install-gpg

Conversation

@ltshb

@ltshb ltshb commented Aug 4, 2025

Copy link
Copy Markdown

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

CLAassistant commented Aug 4, 2025

Copy link
Copy Markdown

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

ltshb commented Aug 4, 2025

Copy link
Copy Markdown
Author

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

@huyz

huyz commented Aug 18, 2025

Copy link
Copy Markdown

It would be great to have this merged.

@MaKaNu

MaKaNu commented Sep 11, 2025

Copy link
Copy Markdown

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

Comment thread tasks/install-apt.yml Outdated
Comment thread tasks/install-apt.yml Outdated
Comment thread tasks/install-apt.yml
Comment thread tasks/install-apt.yml Outdated
Comment thread tasks/install-apt.yml Outdated
Comment thread tasks/install-apt.yml
mode: 'u=rw,go=r'
when: not visual_studio_code_skip_add_repo

- name: Install VS Code (apt)

Copy link
Copy Markdown

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

@ltshb ltshb left a comment

Copy link
Copy Markdown
Author

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.

@MaKaNu MaKaNu left a comment

Copy link
Copy Markdown

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 thread tasks/install-apt.yml Outdated
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
Copy Markdown

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
Copy Markdown
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

@MaKaNu MaKaNu left a comment

Copy link
Copy Markdown

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?

@ltshb

ltshb commented Jan 27, 2026

Copy link
Copy Markdown
Author

@freemanjp it would be very helpful to the community if we could merge this PR. Thanks

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