Skip to content

Commit

Permalink
[Windows] Fix OS in-place upgrade issues from Windows Server 2012 R2 …
Browse files Browse the repository at this point in the history
…and Windows Server 2016 (#578)

Signed-off-by: Diane Wang <dianew@vmware.com>
  • Loading branch information
Tomorrow9 authored May 17, 2024
1 parent 8e2f14c commit 2e891d0
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
---
- name: "Set fact of expected guest OS distribution"
ansible.builtin.set_fact:
win_distr_expected: "{{ 'Microsoft ' ~ win_image_name.split('(')[0].strip() }}"
win_distr_expected: "{{ 'Microsoft ' ~ win_image_name | regex_search('Windows( Server)? ([0-9]+)') ~ ' ' ~ guest_os_edition }}"

- name: "Get VMTools service status in guest OS"
include_tasks: ../utils/win_get_service_status.yml
Expand Down
4 changes: 2 additions & 2 deletions windows/guest_os_inplace_upgrade/mount_upgrade_to_iso.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
- name: "Get CDROM drive mounted with ISO image"
include_tasks: ../utils/win_execute_cmd.yml
vars:
win_powershell_cmd: "(Get-Volume | where-object {$_.DriveType -eq 'CD-ROM' -and $_.OperationalStatus -eq 'OK'}).DriveLetter"
win_powershell_cmd: "(Get-Volume | where-object {$_.DriveType -eq 'CD-ROM' -and $_.Size -ne 0}).DriveLetter"
- name: "Set fact of mounted drive in guest OS"
ansible.builtin.set_fact:
upgrade_to_iso_drive: "{{ win_powershell_cmd_output.stdout_lines[0] }}"
Expand Down Expand Up @@ -67,7 +67,7 @@

- name: "Set fact of Windows Server image keyword"
ansible.builtin.set_fact:
win_upgrade_image_keyword: "*{{ guest_os_edition }} (Desktop Experience)"
win_upgrade_image_keyword: ".*{{ guest_os_edition }}.*Desktop.*|.*SERVER{{ guest_os_edition | upper }}$"
when: guest_os_product_type | lower == 'server'
- name: "Set fact of Windows Client image keyword"
ansible.builtin.set_fact:
Expand Down
11 changes: 3 additions & 8 deletions windows/utils/get_windows_system_info.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,9 @@
- (guest_os_product_type | lower == 'server' and guest_os_build_num | int >= 20348) or (guest_os_product_type | lower == 'client' and guest_os_build_num | int >= 22449)

- name: "Get Windows guest OS edition from distribution info"
block:
- name: "Set fact of Windows guest OS edition info"
ansible.builtin.set_fact:
guest_os_edition_info: "{{ guest_os_ansible_distribution | regex_search('Microsoft (Windows|Windows Server) ([0-9]+) (.*)', '\\3') }}"
- name: "Set fact of Windows guest OS edition info"
ansible.builtin.set_fact:
guest_os_edition: "{{ guest_os_edition_info[0].split(' ')[0] }}"
when: guest_os_edition_info and guest_os_edition_info | length > 0
ansible.builtin.set_fact:
guest_os_edition: >-
{{ guest_os_ansible_distribution | regex_search('Microsoft Windows( Server)? ([0-9]+) (R2 )?(.*)', '\4') | first }}
when: guest_os_ansible_distribution

- name: "Print Windows guest OS information"
Expand Down
8 changes: 5 additions & 3 deletions windows/utils/win_get_driver_installer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,21 @@
{%- elif win_get_driver_installer_name == 'vmxnet3' -%}vmxnet3ndis6
{%- else -%}{%- endif -%}
# Get-ItemPropertyValue cmdlet is not contained in Windows Server 2012 R2
- name: "Get driver installer registry info"
include_tasks: win_execute_cmd.yml
vars:
win_powershell_cmd: |-
if ($(Test-Path -Path "HKLM:\System\CurrentControlSet\Services\{{ win_driver_service }}")) {
Get-ItemPropertyValue -Path "HKLM:\System\CurrentControlSet\Services\{{ win_driver_service }}" -Name 'vwdk.installers'
reg query "HKLM\System\CurrentControlSet\Services\{{ win_driver_service }}" /v 'vwdk.installers' | findstr 'REG'
}
- name: "Set fact of the driver installer info list"
ansible.builtin.set_fact:
win_driver_installer_list: "{{ win_powershell_cmd_output.stdout_lines | select }}"
win_driver_installer_list: "{{ win_powershell_cmd_output.stdout_lines[0].split(' ')[-1] }}"
when:
- win_powershell_cmd_output.stdout_lines is defined
- win_powershell_cmd_output.stdout_lines | length != 0
- win_powershell_cmd_output.stdout_lines | length == 1

- name: "Display the driver installer info list"
ansible.builtin.debug:
Expand Down
7 changes: 6 additions & 1 deletion windows/utils/win_get_image_index.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,15 @@
win_image_index: ''
win_image_name: ''

- name: "Get Windows image info"
include_tasks: ../utils/win_execute_cmd.yml
vars:
win_powershell_cmd: "Get-WindowsImage -ImagePath {{ win_image_file_path }}"

- name: "Get matched Windows image info"
include_tasks: ../utils/win_execute_cmd.yml
vars:
win_powershell_cmd: "(Get-WindowsImage -ImagePath {{ win_image_file_path }} | where-object {$_.ImageName -like '{{ win_image_keyword }}'}) | select ImageIndex, ImageName | ft -hide"
win_powershell_cmd: "(Get-WindowsImage -ImagePath {{ win_image_file_path }} | where-object {$_.ImageName -match '{{ win_image_keyword }}'}) | select ImageIndex, ImageName | ft -hide"

- name: "Set fact of Windows image list"
block:
Expand Down
5 changes: 5 additions & 0 deletions windows/wintools_complete_install_verify/install_vmtools.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,15 @@
fail_msg: "VMware Tools installation setup files are not in D:\\"
success_msg: "VMware Tools installation setup files are in D:\\"

# In Windows Server 2012 R2 guest OS, need to set 'become' to run
# VMware Tools install command
- name: "Execute VMware Tools silent install command in guest"
ansible.windows.win_shell: "{{ vmtools_install_cmd }}"
delegate_to: "{{ vm_guest_ip }}"
ignore_errors: true
become: "{{ 'Windows Server 2012 R2' in guest_os_ansible_distribution }}"
become_method: runas
become_user: "{{ 'Administrator' if ('Windows Server 2012 R2' in guest_os_ansible_distribution) else omit }}"
register: wintools_install_result
async: 600
poll: 0
Expand Down
23 changes: 14 additions & 9 deletions windows/wintools_complete_install_verify/verify_vmtools.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,17 @@
Get usernames of 'vmtoolsd' processes:
{{ win_powershell_cmd_output.stdout_lines }}.
- name: "Get problem device after VMware Tools install"
include_tasks: ../utils/win_get_problem_device.yml
- name: "Check no problem device listed"
ansible.builtin.assert:
that:
- gos_has_problem_device is defined
- not gos_has_problem_device
fail_msg: "Problem devices were found in guest OS, please check listed problem devices: {{ gos_problem_device_list }}"
success_msg: "No problem device is found in guest OS."
# In Windows Server 2012 R2 or older OS there is no cmdlet 'Get-PnpDevice',
# so here only check in newer OS
- name: "Check if there is problem device in Device Manager"
when: guest_os_ansible_distribution_ver is version('6.3.9600.0', '>')
block:
- name: "Get problem device after VMware Tools install"
include_tasks: ../utils/win_get_problem_device.yml
- name: "Check no problem device listed"
ansible.builtin.assert:
that:
- gos_has_problem_device is defined
- not gos_has_problem_device
fail_msg: "Problem devices were found in guest OS, please check listed problem devices: {{ gos_problem_device_list }}"
success_msg: "No problem device is found in guest OS."

0 comments on commit 2e891d0

Please sign in to comment.