|
| 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 |
0 commit comments