From f01dc21acf3caa0b4353ae6fd5930b16d1b1c668 Mon Sep 17 00:00:00 2001 From: Fabio Scotto di Santolo Date: Thu, 2 Apr 2026 16:48:03 +0200 Subject: [PATCH] Set Ubuntu as default Windows Terminal profile --- .../group_vars/workstation_host_windows.yml | 1 + .../tasks/main.yml | 31 +++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/ansible/inventory/group_vars/workstation_host_windows.yml b/ansible/inventory/group_vars/workstation_host_windows.yml index 053769d..e3d2531 100644 --- a/ansible/inventory/group_vars/workstation_host_windows.yml +++ b/ansible/inventory/group_vars/workstation_host_windows.yml @@ -9,6 +9,7 @@ ansible_shell_type: powershell windows_enable_dark_theme: true windows_hide_taskbar_search: true windows_hide_taskbar_widgets: true +windows_terminal_default_profile_name: Ubuntu windows_winget_packages: - id: 7zip.7zip diff --git a/ansible/roles/profile_workstation_host_windows/tasks/main.yml b/ansible/roles/profile_workstation_host_windows/tasks/main.yml index 5de5c71..a248cd7 100644 --- a/ansible/roles/profile_workstation_host_windows/tasks/main.yml +++ b/ansible/roles/profile_workstation_host_windows/tasks/main.yml @@ -192,3 +192,34 @@ loop: "{{ windows_vscode_extensions | default([]) }}" loop_control: label: "{{ item }}" + +- name: Set Windows Terminal default profile to Ubuntu + tags: [packages, wsl] + ansible.windows.win_powershell: + script: | + $terminalSettingsPath = Join-Path $env:LOCALAPPDATA 'Packages\Microsoft.WindowsTerminal_8wekyb3d8bbwe\LocalState\settings.json' + if (-not (Test-Path $terminalSettingsPath)) { + throw 'Windows Terminal settings.json was not found. Launch Windows Terminal once before applying the default profile configuration.' + } + + $settings = Get-Content -Path $terminalSettingsPath -Raw | ConvertFrom-Json + if ($null -eq $settings.profiles -or $null -eq $settings.profiles.list) { + throw 'Windows Terminal settings.json does not contain a profiles.list section.' + } + + $targetProfile = $settings.profiles.list | + Where-Object { $_.name -eq '{{ windows_terminal_default_profile_name }}' } | + Select-Object -First 1 + + if ($null -eq $targetProfile) { + throw "Windows Terminal profile '{{ windows_terminal_default_profile_name }}' was not found. Ensure the Ubuntu WSL profile exists in Windows Terminal first." + } + + if ($settings.defaultProfile -eq $targetProfile.guid) { + $Ansible.Changed = $false + return + } + + $settings.defaultProfile = $targetProfile.guid + $settings | ConvertTo-Json -Depth 100 | Set-Content -Path $terminalSettingsPath -Encoding utf8 + $Ansible.Changed = $true