From 754783827894338d36aefddc38af82de2818cfab Mon Sep 17 00:00:00 2001 From: Fabio Scotto di Santolo Date: Thu, 2 Apr 2026 15:20:04 +0200 Subject: [PATCH] Support user-scoped winget installs on Windows --- .../group_vars/workstation_host_windows.yml | 1 + .../tasks/main.yml | 17 ++++++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/ansible/inventory/group_vars/workstation_host_windows.yml b/ansible/inventory/group_vars/workstation_host_windows.yml index 04d0bfd..4d6ead9 100644 --- a/ansible/inventory/group_vars/workstation_host_windows.yml +++ b/ansible/inventory/group_vars/workstation_host_windows.yml @@ -31,6 +31,7 @@ windows_winget_packages: name: Postman - id: Spotify.Spotify name: Spotify + scope: user - id: Telegram.TelegramDesktop name: Telegram Desktop diff --git a/ansible/roles/profile_workstation_host_windows/tasks/main.yml b/ansible/roles/profile_workstation_host_windows/tasks/main.yml index 117a500..336ab44 100644 --- a/ansible/roles/profile_workstation_host_windows/tasks/main.yml +++ b/ansible/roles/profile_workstation_host_windows/tasks/main.yml @@ -124,13 +124,28 @@ script: | $packageId = '{{ item.id }}' $packageName = '{{ item.name | default(item.id) }}' + $packageScope = '{{ item.scope | default('' ) }}' + $installArgs = @( + 'install' + '--id', $packageId + '--exact' + '--silent' + '--accept-package-agreements' + '--accept-source-agreements' + '--disable-interactivity' + ) + + if (-not [string]::IsNullOrWhiteSpace($packageScope)) { + $installArgs += @('--scope', $packageScope) + } + $installed = & winget list --id $packageId --exact --accept-source-agreements --disable-interactivity 2>$null if ($LASTEXITCODE -eq 0 -and $installed -match [regex]::Escape($packageId)) { $Ansible.Changed = $false return } - & winget install --id $packageId --exact --silent --accept-package-agreements --accept-source-agreements --disable-interactivity + & winget @installArgs if ($LASTEXITCODE -ne 0) { throw "Failed to install $packageName with winget" }