Skip to content

Commit 3bead55

Browse files
committed
add check win processes
Signed-off-by: dw035535 <diane.wang@broadcom.com>
1 parent 1397e37 commit 3bead55

File tree

4 files changed

+109
-5
lines changed

4 files changed

+109
-5
lines changed

windows/guest_customization/win_gosc_verify.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
include_tasks: check_runonce_command.yml
2828
- name: "Check timezone configured"
2929
include_tasks: check_timezone.yml
30+
- name: "Check Windows readiness"
31+
include_tasks: win_check_os_readiness.yml
3032
- name: "Get 'explorer.exe' process status"
3133
include_tasks: ../utils/win_get_explorer_process.yml
3234
- name: "Check 'explorer.exe' process status"
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Copyright 2025 VMware, Inc.
2+
# SPDX-License-Identifier: BSD-2-Clause
3+
---
4+
# Get these 2 processes' info to check if the Windows is actively installing or
5+
# configuring something.
6+
# "TiWorker.exe (Windows Modules Installer Worker)" is the primary process
7+
# responsible for installing updates and modifying system files.
8+
# "msiexec.exe" is the Windows Installer engine, if running as SYSTEM user (Session 0),
9+
# it means a background installation (like a driver or managed app) is happening.
10+
#
11+
- name: "Set facts of the commands for checking Windows status"
12+
ansible.builtin.set_fact:
13+
check_tiworker: "Get-Process TiWorker -ErrorAction SilentlyContinue | Format-List -Property *"
14+
check_msiexec: "Get-Process msiexec -IncludeUserName -ErrorAction SilentlyContinue | Where-Object {$_.UserName -match 'SYSTEM'} | Format-List -Property *"
15+
16+
- name: "Get 'TiWorker.exe' process info"
17+
include_tasks: win_execute_cmd.yml
18+
vars:
19+
win_powershell_cmd: "{{ check_tiworker }}"
20+
win_execute_cmd_ignore_error: true
21+
22+
- name: "Save the result of getting 'TiWorker.exe' process info"
23+
ansible.builtin.set_fact:
24+
check_tiworker_result: "{{ win_powershell_cmd_output }}"
25+
26+
- name: "Get 'msiexec.exe' process info"
27+
include_tasks: win_execute_cmd.yml
28+
vars:
29+
win_powershell_cmd: "{{ check_msiexec }}"
30+
win_execute_cmd_ignore_error: true
31+
32+
- name: "Save the result of getting 'msiexec.exe' process info"
33+
ansible.builtin.set_fact:
34+
check_msiexec_result: "{{ win_powershell_cmd_output }}"
35+
36+
- name: "Set fact of Windows is actively installing updates"
37+
ansible.builtin.set_fact:
38+
os_in_active_updates: true
39+
when: >
40+
(check_tiworker_result.rc is defined and check_tiworker_result.rc == 0) or
41+
(check_msiexec_result.stdout is defined and check_msiexec_result.stdout | length != 0)
42+
43+
- name: "Set fact of Windows is not actively installing updates"
44+
ansible.builtin.set_fact:
45+
os_in_active_updates: false
46+
when:
47+
- check_tiworker_result.rc is defined and check_tiworker_result.rc != 0
48+
- check_msiexec_result.stdout is defined and check_msiexec_result.stdout | length == 0
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Copyright 2025 VMware, Inc.
2+
# SPDX-License-Identifier: BSD-2-Clause
3+
---
4+
# Check Windows system readiness after booting up
5+
#
6+
- name: "Initialize the readiness of Windows"
7+
ansible.builtin.set_fact:
8+
os_in_active_updates: false
9+
10+
- name: "Retry to check if Windows is actively installing updates"
11+
include_tasks: win_check_active_update.yml
12+
loop: "{{ range(1, 11) | list }}"
13+
loop_control:
14+
pause: 3
15+
break_when:
16+
- os_in_active_updates
17+
18+
- name: "Debug message"
19+
ansible.builtin.debug:
20+
msg: "Not get the processes that can indicating the Windows is actively installing updates in 30s."
21+
when: not os_in_active_updates
22+
23+
- name: "Debug message"
24+
ansible.builtin.debug:
25+
msg: "Windows guest OS is actively installing updates or configuring something."
26+
when: os_in_active_updates
27+
28+
- name: "Wait for Windows updates installation completes"
29+
when: os_in_active_updates
30+
block:
31+
- name: "Retry to check if Windows completes installing updates"
32+
include_tasks: win_check_active_update.yml
33+
loop: "{{ range(1, 201) | list }}"
34+
loop_control:
35+
pause: 3
36+
break_when:
37+
- not os_in_active_updates
38+
- name: "Debug message"
39+
ansible.builtin.debug:
40+
msg: "Still can get the processes that indicating the Windows is actively installing updates in 600s."
41+
when: os_in_active_updates
42+
- name: "Debug message"
43+
ansible.builtin.debug:
44+
msg: "Windows guest OS completes the updates install."
45+
when: not os_in_active_updates

windows/utils/win_get_explorer_process.yml

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
# Description:
55
# Get process 'explorer.exe' in Windows guest OS to check
66
# if there is black screen issue occurs.
7+
# Parameters:
8+
# win_get_explorer_timeout: the retry time in seconds to get
9+
# the status of process 'explorer.exe'.
710
# Return:
811
# win_explorer_running: true or false. Whether the process
912
# 'explorer.exe' is running in guest OS.
@@ -12,11 +15,17 @@
1215
ansible.builtin.set_fact:
1316
win_explorer_running: false
1417

15-
- name: "Get the status of process 'explorer.exe'"
16-
include_tasks: win_execute_cmd.yml
17-
vars:
18-
win_powershell_cmd: "Get-Process -Name explorer"
19-
win_execute_cmd_ignore_error: true
18+
- name: "Wait for 'explorer.exe' process starting"
19+
ansible.windows.win_shell: 'Get-Process -Name explorer'
20+
delegate_to: "{{ vm_guest_ip }}"
21+
register: get_service_status
22+
delay: 5
23+
retries: "{{ (win_get_explorer_timeout | default(300) / 5) | round | int }}"
24+
until:
25+
- get_service_status.rc is defined
26+
- get_service_status.rc == 0
27+
ignore_errors: true
28+
ignore_unreachable: true
2029

2130
- name: "Set fact of the status of process 'explorer.exe'"
2231
ansible.builtin.set_fact:

0 commit comments

Comments
 (0)