Skip to content

Commit

Permalink
add remove appx package
Browse files Browse the repository at this point in the history
Signed-off-by: Diane Wang <dianew@vmware.com>
  • Loading branch information
Tomorrow9 committed Dec 7, 2023
1 parent 31d2550 commit 7d2947b
Show file tree
Hide file tree
Showing 16 changed files with 272 additions and 233 deletions.
60 changes: 32 additions & 28 deletions windows/guest_customization/check_autologon_count.yml
Original file line number Diff line number Diff line change
@@ -1,46 +1,50 @@
# Copyright 2021-2023 VMware, Inc.
# SPDX-License-Identifier: BSD-2-Clause
---
# Get auto Admin logon value after gosc
- include_tasks: ../utils/win_execute_cmd.yml
# Check logon as Administrator automatically is set in guest OS
- name: "Initialize the registry value of logon as Administrator automatically"
ansible.builtin.set_fact:
auto_admin_logon: 0

- name: "Get logon as Administrator automatically registry value"
include_tasks: ../utils/win_execute_cmd.yml
vars:
win_powershell_cmd: "(get-itemproperty -path 'HKLM:\\software\\microsoft\\Windows NT\\CurrentVersion\\Winlogon').AutoAdminLogon"
- name: Set fact of the Admin auto logon
win_powershell_cmd: >-
(Get-ItemProperty -path 'HKLM:\\software\\microsoft\\Windows NT\\CurrentVersion\\Winlogon').AutoAdminLogon
- name: "Set fact of logon as Administrator automatically registry value"
ansible.builtin.set_fact:
auto_admin_logon: "{{ win_powershell_cmd_output.stdout_lines[0] }}"
- ansible.builtin.debug:
msg: "Get auto Admin logon enabled value: {{ auto_admin_logon }}"
when: enable_debug
when:
- win_powershell_cmd_output.stdout_lines is defined
- win_powershell_cmd_output.stdout_lines | length != 0

- name: "Check logon as Administrator automatically is enabled"
ansible.builtin.assert:
that:
- "{{ auto_admin_logon | int == 1 }}"
success_msg: "Logon as Administrator automatically is enabled in guest OS."
fail_msg: "Logon as Administrator automatically registry value '{{ auto_admin_logon }}' is not equal to 1."

- name: Get auto admin logon count value after GOSC
ansible.windows.win_shell: "(get-itemproperty -path 'HKLM:\\software\\microsoft\\Windows NT\\CurrentVersion\\Winlogon').AutoLogonCount"
- name: "Get number of times to logon as Administrator automatically"
ansible.windows.win_shell: >-
(Get-ItemProperty -path 'HKLM:\\software\\microsoft\\Windows NT\\CurrentVersion\\Winlogon').AutoLogonCount
register: get_auto_logon_count
delegate_to: "{{ vm_guest_ip }}"
until:
- get_auto_logon_count.stdout_lines is defined
- get_auto_logon_count.stdout_lines | length != 0
- get_auto_logon_count.stdout_lines[0] | int == customize_autologon_count | int - 1
- get_auto_logon_count.stdout_lines[0] | int == win_gosc_spec.gosc_autologon_count | int - 1
retries: 100
delay: 3
ignore_errors: true

- name: "Check auto admin logon count value after GOSC"
- name: "Check number of times to logon as Administrator automatically"
ansible.builtin.assert:
that:
- get_auto_logon_count is defined
- get_auto_logon_count.stdout_lines | length != 0
- get_auto_logon_count.stdout_lines[0] | int == customize_autologon_count | int - 1
- not get_auto_logon_count.failed
success_msg: "Number of times to logon as Administrator automatically is set correctly: {{ get_auto_logon_count.stdout_lines[0] }}."
fail_msg: >-
Auto admin logon count value after GOSC is still incorrect after 300 seconds.
Current auto admin logon count value is '{{ get_auto_logon_count.stdout_lines[0] | int | default("") }}',
not expected '{{ customize_autologon_count | int - 1 }}'.
- ansible.builtin.debug:
msg: "Get remain auto logon count: {{ get_auto_logon_count.stdout_lines[0] }}"
when: enable_debug

- name: Check auto admin logon enabled and count is accurate
ansible.builtin.assert:
that:
- "{{ auto_admin_logon | int == 1 }}"
success_msg: "Auto Admin logon is enabled and customized auto logon count is accurate."
fail_msg: "Auto Admin logon is not enabled."
The number of times to logon as Administrator automatically is incorrect after 300 seconds.
Got value '{{ get_auto_logon_count.stdout_lines[0] | default('') }}' in guest OS after GOSC,
expected value is '{{ win_gosc_spec.gosc_autologon_count | int - 1 }}'.
16 changes: 16 additions & 0 deletions windows/guest_customization/check_ip_hostname.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Copyright 2023 VMware, Inc.
# SPDX-License-Identifier: BSD-2-Clause
---
- name: "Wait for VM IP address after GOSC"
include_tasks: ../../common/vm_wait_guest_ip.yml
vars:
wait_ipv4: "{{ win_gosc_spec.gosc_ip | default('') }}"

- name: "Update in-memory inventory after GOSC"
include_tasks: ../utils/win_update_inventory.yml
when: gosc_network_type == "dhcp"

- name: "Wait for guest OS hostname after GOSC"
include_tasks: ../../common/vm_wait_guest_hostname.yml
vars:
wait_guest_hostname: "{{ win_gosc_spec.gosc_hostname }}"
19 changes: 11 additions & 8 deletions windows/guest_customization/check_runonce_command.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,19 @@
# SPDX-License-Identifier: BSD-2-Clause
---
# Check runonce command executed in guest OS
- name: Display the run once command
ansible.builtin.debug: var=customize_runonce
- name: "Display the GOSC run once command"
ansible.builtin.debug: var=win_gosc_spec.gosc_runonce

- include_tasks: ../utils/win_execute_cmd.yml
- name: "Get GOSC run once command output file"
include_tasks: ../utils/win_execute_cmd.yml
vars:
win_powershell_cmd: "get-content -Path C:\\gosc_runonce.txt"
win_powershell_cmd: "Get-Content -Path {{ win_gosc_spec.gosc_echo_file }}"

- name: Check run once command executed
- name: "Check GOSC run once command executed in guest OS"
ansible.builtin.assert:
that:
- "{{ win_powershell_cmd_output.stdout_lines[0].strip() == customize_runonce_echo_string.strip() }}"
success_msg: "Run once command executed and test file created"
fail_msg: "Run once command not executed or test file not created"
- win_powershell_cmd_output.stdout_lines is defined
- win_powershell_cmd_output.stdout_lines | length != 0
- "{{ win_powershell_cmd_output.stdout_lines[0].strip() == win_gosc_spec.gosc_echo_string.strip() }}"
success_msg: "Run once command is executed in guest OS."
fail_msg: "Run once command is not executed successfully in guest OS."
33 changes: 19 additions & 14 deletions windows/guest_customization/check_timezone.yml
Original file line number Diff line number Diff line change
@@ -1,23 +1,28 @@
# Copyright 2021-2023 VMware, Inc.
# SPDX-License-Identifier: BSD-2-Clause
---
# Check timezone name after gos customization
- ansible.builtin.debug:
msg: "Configured timezone: {{ customize_timezone_name }}"
when: enable_debug is defined and enable_debug
- name: Check timezone in guest OS
# Check timezone name after GOS customization
- name: "Print timezone name in Windows GOSC spec"
ansible.builtin.debug:
msg: "Configured timezone in GOSC spec: {{ win_gosc_spec.gosc_timezone_name }}"

- name: "Get timezone info in guest OS"
include_tasks: ../utils/win_execute_cmd.yml
vars:
win_powershell_cmd: "tzutil /g"
- name: Set fact of the timezone in guest OS

- name: "Set fact of the timezone in guest OS"
ansible.builtin.set_fact:
timezone_after_customize: "{{ win_powershell_cmd_output.stdout_lines[0] if not win_powershell_cmd_output.failed else 'NA'}}"
- ansible.builtin.debug:
msg: "Get timezone after customize: {{ timezone_after_customize }}"
- name: Check returned timezone name is the specified one
timezone_after_gosc: "{{ win_powershell_cmd_output.stdout_lines[0] }}"
when:
- win_powershell_cmd_output.stdout_lines is defined
- win_powershell_cmd_output.stdout_lines | length != 0

- name: "Check customized timezone in guest OS"
ansible.builtin.assert:
that:
- "{{ not win_powershell_cmd_output.failed }}"
- "{{ win_powershell_cmd_output.stdout_lines[0] == customize_timezone_name }}"
success_msg: "Check customized timezone in guest OS succeed."
fail_msg: "Check customized timezone in guest OS failed."
- "{{ timezone_after_gosc == win_gosc_spec.gosc_timezone_name }}"
success_msg: "Timezone '{{ timezone_after_gosc }}' is set by GOSC successfully in guest OS."
fail_msg: >-
Got timezone in guest OS '{{ timezone_after_gosc }}',
which is not the one set in GOSC sepc '{{ win_gosc_spec.gosc_timezone_name }}'.
27 changes: 15 additions & 12 deletions windows/guest_customization/get_gosc_logs_network.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,31 @@
# SPDX-License-Identifier: BSD-2-Clause
---
# Fetch log files from Windows guest OS to local
- name: Initialize the absolute path of GOSC log folders
- name: "Initialize the absolute directory path list of GOSC log"
ansible.builtin.set_fact:
gosc_win_log_folders_src: []
separator: '\'
win_gosc_log_dir: []

- name: Set fact of the GOSC log paths
- name: "Set fact of the relative directory path list of GOSC log"
ansible.builtin.set_fact:
gosc_win_log_folders:
win_gosc_log_dir_rel:
- 'Temp\vmware-imc\'
- 'System32\Sysprep\Panther\'
- 'Panther\'
- 'Debug\'
- name: Set fact of the absolute path of GOSC log folders

- name: "Set fact of the absolute directory path list of GOSC log"
ansible.builtin.set_fact:
gosc_win_log_folders_src: "{{ gosc_win_log_folders_src + [win_dir ~ separator ~ item] }}"
with_items: "{{ gosc_win_log_folders }}"
- name: Display the GOSC log paths
ansible.builtin.debug: var=gosc_win_log_folders_src
win_gosc_log_dir: "{{ win_gosc_log_dir + [win_windows_dir ~ win_dir_separator ~ item] }}"
with_items: "{{ win_gosc_log_dir_rel }}"
no_log: true

- name: "Display the directory path list of GOSC log"
ansible.builtin.debug: var=win_gosc_log_dir

- include_tasks: ../utils/win_get_folder.yml
- name: "Get GOSC log files from guest OS"
include_tasks: ../utils/win_get_folder.yml
vars:
win_get_folder_dst_path: "{{ current_test_log_folder }}"
with_items: "{{ gosc_win_log_folders_src }}"
with_items: "{{ win_gosc_log_dir }}"
loop_control:
loop_var: win_get_folder_src_path
28 changes: 13 additions & 15 deletions windows/guest_customization/get_gosc_logs_no_network.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,15 @@
# SPDX-License-Identifier: BSD-2-Clause
---
# Fetch log files from Windows guest OS to local
- name: "Initialize the dict of source log files and dest path"
- name: "Initialize the GOSC log files source and dest paths"
ansible.builtin.set_fact:
separator: '\'
source_log_list: []
dest_log_list: []
gosc_win_log_src_dest: {}
win_gosc_log_files: []
win_gosc_log_files_dst: []
win_gosc_log_src_dest: {}

- name: "Set fact of the GOSC log files' paths"
- name: "Set fact of the relative file path list of GOSC log"
ansible.builtin.set_fact:
gosc_win_log_files:
win_gosc_log_files_rel:
- 'Temp\vmware-imc\guestcust.log'
- 'Temp\vmware-imc\toolsDeployPkg.log'
- 'System32\Sysprep\Panther\setupact.log'
Expand All @@ -24,24 +23,23 @@
- 'Debug\PASSWD.LOG'
- 'Debug\sammui.log'

- name: "Set fact of the absolute log files path list"
- name: "Set fact of the absolute file path list of GOSC log"
ansible.builtin.set_fact:
source_log_list: "{{ source_log_list + [win_dir ~ separator ~ item] }}"
dest_log_list: "{{ dest_log_list + [current_test_log_folder ~ '/' ~ item.split(separator) | join('/')] }}"
with_items: "{{ gosc_win_log_files }}"
no_log: true
win_gosc_log_files: "{{ win_gosc_log_files + [win_windows_dir ~ win_dir_separator ~ item] }}"
win_gosc_log_files_dst: "{{ win_gosc_log_files_dst + [current_test_log_folder ~ '/' ~ item.split(win_dir_separator) | join('/')] }}"
with_items: "{{ win_gosc_log_files_rel }}"

- name: "Set fact of the source and dest log files path dict"
ansible.builtin.set_fact:
gosc_win_log_src_dest: "{{ dict(source_log_list | zip(dest_log_list)) }}"
win_gosc_log_src_dest: "{{ dict(win_gosc_log_files | zip(win_gosc_log_files_dst)) }}"

- name: "Display the GOSC log files to be fetched"
ansible.builtin.debug: var=gosc_win_log_src_dest
ansible.builtin.debug: var=win_gosc_log_src_dest

- name: "Fetch GOSC log files from guest OS"
include_tasks: ../../common/vm_guest_file_operation.yml
vars:
operation: "fetch_file"
src_path: "{{ item.key }}"
dest_path: "{{ item.value }}"
loop: "{{ gosc_win_log_src_dest | dict2items }}"
loop: "{{ win_gosc_log_src_dest | dict2items }}"
4 changes: 2 additions & 2 deletions windows/guest_customization/gosc_sanity_dhcp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
# Description:
# This test case is used for check guest OS customization (GOSC)
# with DHCP network configuration. If VMware Tools is not installed,
# the test result is 'No Run'.
# the test result is 'Blocked'.
# Note: VM guest OS customization requires vCenter server.
#
- name: gosc_sanity_dhcp
hosts: localhost
gather_facts: false
vars:
customize_network_type: "dhcp"
gosc_network_type: "dhcp"
tasks:
- name: "GOSC test with DHCP network configure"
include_tasks: win_gosc_workflow.yml
4 changes: 2 additions & 2 deletions windows/guest_customization/gosc_sanity_staticip.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
# Description:
# This test case is used for check guest OS customization (GOSC)
# with static network configuration. If VMware Tools is not installed,
# the test result is 'No Run'.
# the test result is 'Blocked'.
# Note: VM guest OS customization requires vCenter server.
#
- name: gosc_sanity_staticip
hosts: localhost
gather_facts: false
vars:
customize_network_type: "static"
gosc_network_type: "static"
tasks:
- name: "GOSC test with static network configure"
include_tasks: win_gosc_workflow.yml
38 changes: 11 additions & 27 deletions windows/guest_customization/uninstall_onedrive.yml
Original file line number Diff line number Diff line change
@@ -1,46 +1,30 @@
# Copyright 2022-2023 VMware, Inc.
# SPDX-License-Identifier: BSD-2-Clause
---
- name: "Set fact of OneDrive setup exe file path for Windows 11 GA"
- name: "Set fact of OneDrive setup file path for Windows 11 GA"
ansible.builtin.set_fact:
one_drive_setup_exe: "C:\\Windows\\SysWOW64\\OneDriveSetup.exe"
when:
- guest_os_ansible_distribution_ver == '10.0.22000.0'
- name: Set fact of OneDrive setup exe file path
when: guest_os_ansible_distribution_ver == '10.0.22000.0'

- name: "Set fact of OneDrive setup file path"
ansible.builtin.set_fact:
one_drive_setup_exe: "C:\\Windows\\System32\\OneDriveSetup.exe"
when: one_drive_setup_exe is undefined

# Check OneDrive setup exe file exists
- include_tasks: ../utils/win_check_file_exist.yml
- name: "Check if OneDrive setup file exists"
include_tasks: ../utils/win_check_file_exist.yml
vars:
win_check_file_exist_file: "{{ one_drive_setup_exe }}"

# Uninstall OneDrive when predefined setup exe file exists
- include_tasks: ../utils/win_execute_cmd.yml
- name: "Uninstall OneDrive"
include_tasks: ../utils/win_execute_cmd.yml
vars:
win_powershell_cmd: "Start-Process -NoNewWindow -Wait -FilePath {{ one_drive_setup_exe }} -ArgumentList '/uninstall'"
when:
- win_check_file_exist_result is defined
- win_check_file_exist_result

# Get installed OneDrive appx package name
- include_tasks: ../utils/win_execute_cmd.yml
vars:
win_powershell_cmd: "(Get-AppxPackage -AllUsers | Where PackageFullName -Like '*OneDriveSync*').PackageFullName"

- name: Set fact of OneDrive Sync appx package name
ansible.builtin.set_fact:
one_drive_appx_package_name: "{{ win_powershell_cmd_output.stdout_lines[0] }}"
when:
- win_powershell_cmd_output is defined
- "'stdout_lines' in win_powershell_cmd_output"
- win_powershell_cmd_output.stdout_lines | length != 0
- win_powershell_cmd_output.stdout_lines[0]

- include_tasks: ../utils/win_execute_cmd.yml
- name: "Remove OneDriveSync Appx package"
include_tasks: ../utils/win_remove_appx_package.yml
vars:
win_powershell_cmd: "Remove-AppxPackage -Package {{ one_drive_appx_package_name }}"
when:
- one_drive_appx_package_name is defined
- one_drive_appx_package_name
win_appx_package: "OneDriveSync"
Loading

0 comments on commit 7d2947b

Please sign in to comment.