Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Windows] Add removing Copilot appx package before running GOSC test cases #596

Merged
merged 4 commits into from
Jun 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion windows/deploy_vm/deploy_vm_from_iso.yml
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@
- name: "Get VM IP address"
include_tasks: ../../common/vm_get_ip.yml
vars:
vm_get_ip_timeout: 3600
vm_get_ip_timeout: 5400

- name: "Check WinRM is connectable"
include_tasks: ../utils/win_check_winrm.yml
Expand Down
10 changes: 8 additions & 2 deletions windows/guest_customization/handle_guest_known_issues.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,23 @@
# https://kb.vmware.com/s/article/87307
- name: "Workaround for SYSPREP error caused by Appx package"
block:
- name: "Remove BingSearch Appx package in Windows Client"
- name: "Remove Appx packages in Windows Client"
include_tasks: ../utils/win_remove_appx_package.yml
vars:
win_appx_package: "BingSearch"
win_remove_appx_ignore_errors: true
Tomorrow9 marked this conversation as resolved.
Show resolved Hide resolved
loop:
- "BingSearch"
- "Microsoft.Copilot"
loop_control:
loop_var: win_appx_package
when:
- guest_os_ansible_distribution_ver is version('10.0.22000.0', '>=')
- guest_os_product_type | lower == 'client'
- name: "Remove Edge.Stable Appx package in Windows Server"
include_tasks: ../utils/win_remove_appx_package.yml
vars:
win_appx_package: "Edge.Stable"
win_remove_appx_ignore_errors: true
when: guest_os_product_type | lower == 'server'

# Parameter 'uninstall_onedrive' is used for internal testing only
Expand Down
41 changes: 24 additions & 17 deletions windows/utils/win_remove_appx_package.yml
Original file line number Diff line number Diff line change
@@ -1,40 +1,47 @@
# Copyright 2023-2024 VMware, Inc.
# SPDX-License-Identifier: BSD-2-Clause
---
# Remove installed Appx package in Windows guest OS
# Remove specified installed Appx package in Windows guest OS
# Parameters:
# win_appx_package: the keyword in Appx package name
# win_appx_package: the keyword in the fullname of Appx package.
# win_remove_appx_ignore_errors (optional): whether to ignore errors
# when getting and removing specified Appx packages. Default is false.
#
- name: "Check required parameter"
ansible.builtin.assert:
that:
- win_appx_package is defined
- win_appx_package
fail_msg: "Parameter 'win_appx_package' is required to be set to a keyword of Appx package name."
fail_msg: "Parameter 'win_appx_package' is required to be set to a keyword of Appx package's fullname."

- name: "Initialize installed Appx package name"
- name: "Initialize the list of installed Appx packages"
ansible.builtin.set_fact:
win_appx_package_name: ''
win_appx_packages_list: []

- name: "Get installed Appx package"
- name: "Get installed Appx packages with keyword in the fullname"
include_tasks: win_execute_cmd.yml
vars:
win_powershell_cmd: "(Get-AppxPackage -AllUsers | Where PackageFullName -Like '*{{ win_appx_package }}*').PackageFullName"
win_powershell_cmd: "(Get-AppxPackage -AllUsers -Name '*{{ win_appx_package }}*').PackageFullName"
win_execute_cmd_ignore_error: "{{ win_remove_appx_ignore_errors | default(false) }}"

- name: "Set fact of installed Appx package name"
- name: "Set fact of the list of installed Appx packages"
ansible.builtin.set_fact:
win_appx_package_name: "{{ win_powershell_cmd_output.stdout_lines[0] }}"
win_appx_packages_list: "{{ win_powershell_cmd_output.stdout_lines | select }}"
when:
- win_powershell_cmd_output.stdout_lines is defined
- win_powershell_cmd_output.stdout_lines | length != 0

- name: "Remove installed Appx package"
include_tasks: win_execute_cmd.yml
vars:
win_powershell_cmd: "Remove-AppxPackage -Package {{ win_appx_package_name }}"
when: win_appx_package_name
- name: "Remove Appx packages got with specified keyword"
when: win_appx_packages_list | length > 0
block:
- name: "Remove Appx package in guest OS"
include_tasks: win_execute_cmd.yml
vars:
win_powershell_cmd: "Remove-AppxPackage -Package {{ item }}"
win_execute_cmd_ignore_error: "{{ win_remove_appx_ignore_errors | default(false) }}"
loop: "{{ win_appx_packages_list }}"

- name: "No Appx package"
- name: "Not get installed Appx package"
ansible.builtin.debug:
msg: "Not get installed Appx package with '{{ win_appx_package }}' in the name, skip removing task."
when: not win_appx_package_name
msg: "Not get installed Appx package with keyword '{{ win_appx_package }}' in the fullname, skip removing task."
when: win_appx_packages_list | length == 0