From 727b7939dda80e69e7c7b76c780e55133aac09bf Mon Sep 17 00:00:00 2001 From: Diane Wang Date: Thu, 9 May 2024 03:18:33 +0000 Subject: [PATCH 01/14] add get Windows image info Signed-off-by: Diane Wang --- windows/utils/win_get_image_index.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/windows/utils/win_get_image_index.yml b/windows/utils/win_get_image_index.yml index 705554e84..5eee3354c 100644 --- a/windows/utils/win_get_image_index.yml +++ b/windows/utils/win_get_image_index.yml @@ -26,6 +26,11 @@ 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: From a9d68f843ef8e01ed37fb13a93dce85cbe8afbf8 Mon Sep 17 00:00:00 2001 From: Diane Wang Date: Thu, 9 May 2024 08:03:00 +0000 Subject: [PATCH 02/14] update get image index Signed-off-by: Diane Wang --- windows/guest_os_inplace_upgrade/mount_upgrade_to_iso.yml | 2 +- windows/utils/win_get_image_index.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/windows/guest_os_inplace_upgrade/mount_upgrade_to_iso.yml b/windows/guest_os_inplace_upgrade/mount_upgrade_to_iso.yml index dff576a36..c107b2ac2 100644 --- a/windows/guest_os_inplace_upgrade/mount_upgrade_to_iso.yml +++ b/windows/guest_os_inplace_upgrade/mount_upgrade_to_iso.yml @@ -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 Experience\)$|.*SERVER{{ guest_os_edition | higher }}$" when: guest_os_product_type | lower == 'server' - name: "Set fact of Windows Client image keyword" ansible.builtin.set_fact: diff --git a/windows/utils/win_get_image_index.yml b/windows/utils/win_get_image_index.yml index 5eee3354c..3884c1172 100644 --- a/windows/utils/win_get_image_index.yml +++ b/windows/utils/win_get_image_index.yml @@ -34,7 +34,7 @@ - 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: From 5d2592524e7235c7adfaecf2f0feb79a616fb2f0 Mon Sep 17 00:00:00 2001 From: Diane Wang Date: Sat, 11 May 2024 04:23:51 +0000 Subject: [PATCH 03/14] fix syntax issue Signed-off-by: Diane Wang --- windows/guest_os_inplace_upgrade/mount_upgrade_to_iso.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/windows/guest_os_inplace_upgrade/mount_upgrade_to_iso.yml b/windows/guest_os_inplace_upgrade/mount_upgrade_to_iso.yml index c107b2ac2..eac41ca2a 100644 --- a/windows/guest_os_inplace_upgrade/mount_upgrade_to_iso.yml +++ b/windows/guest_os_inplace_upgrade/mount_upgrade_to_iso.yml @@ -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\)$|.*SERVER{{ guest_os_edition | higher }}$" + win_upgrade_image_keyword: ".*{{ guest_os_edition }}.*Desktop.*|.*SERVER{{ guest_os_edition | higher }}$" when: guest_os_product_type | lower == 'server' - name: "Set fact of Windows Client image keyword" ansible.builtin.set_fact: From a7fcaf8c6430832d61603faa93fe947770102878 Mon Sep 17 00:00:00 2001 From: Diane Wang Date: Sat, 11 May 2024 04:51:20 +0000 Subject: [PATCH 04/14] fix syntax error Signed-off-by: Diane Wang --- windows/guest_os_inplace_upgrade/mount_upgrade_to_iso.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/windows/guest_os_inplace_upgrade/mount_upgrade_to_iso.yml b/windows/guest_os_inplace_upgrade/mount_upgrade_to_iso.yml index eac41ca2a..00aaa1b8b 100644 --- a/windows/guest_os_inplace_upgrade/mount_upgrade_to_iso.yml +++ b/windows/guest_os_inplace_upgrade/mount_upgrade_to_iso.yml @@ -67,7 +67,7 @@ - name: "Set fact of Windows Server image keyword" ansible.builtin.set_fact: - win_upgrade_image_keyword: ".*{{ guest_os_edition }}.*Desktop.*|.*SERVER{{ guest_os_edition | higher }}$" + 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: From a7800d1e7870e89e8c8e6b4ca1f7f6cd84f42eae Mon Sep 17 00:00:00 2001 From: Diane Wang Date: Sat, 11 May 2024 07:16:27 +0000 Subject: [PATCH 05/14] fix guest fullname compare issue Signed-off-by: Diane Wang --- windows/guest_os_inplace_upgrade/check_after_gos_upgrade.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/windows/guest_os_inplace_upgrade/check_after_gos_upgrade.yml b/windows/guest_os_inplace_upgrade/check_after_gos_upgrade.yml index bad3e3c89..cba6ad9aa 100644 --- a/windows/guest_os_inplace_upgrade/check_after_gos_upgrade.yml +++ b/windows/guest_os_inplace_upgrade/check_after_gos_upgrade.yml @@ -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|Windows Server) ([0-9]+)') ~ ' ' ~ guest_os_edition }}" - name: "Get VMTools service status in guest OS" include_tasks: ../utils/win_get_service_status.yml From 44e7686b49413391a841d0c545f2abe27abb309b Mon Sep 17 00:00:00 2001 From: Diane Wang Date: Mon, 13 May 2024 03:24:24 +0000 Subject: [PATCH 06/14] address comments Signed-off-by: Diane Wang --- windows/guest_os_inplace_upgrade/check_after_gos_upgrade.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/windows/guest_os_inplace_upgrade/check_after_gos_upgrade.yml b/windows/guest_os_inplace_upgrade/check_after_gos_upgrade.yml index cba6ad9aa..4bfca6ac8 100644 --- a/windows/guest_os_inplace_upgrade/check_after_gos_upgrade.yml +++ b/windows/guest_os_inplace_upgrade/check_after_gos_upgrade.yml @@ -3,7 +3,7 @@ --- - name: "Set fact of expected guest OS distribution" ansible.builtin.set_fact: - win_distr_expected: "{{ 'Microsoft ' ~ win_image_name | regex_search('(Windows|Windows Server) ([0-9]+)') ~ ' ' ~ guest_os_edition }}" + 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 From 10fa9c367395c220506efb342749c0eb168b2aca Mon Sep 17 00:00:00 2001 From: Diane Wang Date: Tue, 14 May 2024 06:32:53 +0000 Subject: [PATCH 07/14] fix no cmdlets issue Signed-off-by: Diane Wang --- windows/utils/win_get_driver_installer.yml | 13 ++++++++--- .../verify_vmtools.yml | 23 +++++++++++-------- 2 files changed, 24 insertions(+), 12 deletions(-) diff --git a/windows/utils/win_get_driver_installer.yml b/windows/utils/win_get_driver_installer.yml index edc88156a..3d1b09beb 100644 --- a/windows/utils/win_get_driver_installer.yml +++ b/windows/utils/win_get_driver_installer.yml @@ -24,19 +24,26 @@ {%- 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' } + +# 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' +# } + - 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: diff --git a/windows/wintools_complete_install_verify/verify_vmtools.yml b/windows/wintools_complete_install_verify/verify_vmtools.yml index 1ccce2cb6..754e3bf2e 100644 --- a/windows/wintools_complete_install_verify/verify_vmtools.yml +++ b/windows/wintools_complete_install_verify/verify_vmtools.yml @@ -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." From 2f46c02af3675ce090231b9e75b60b86f3566afb Mon Sep 17 00:00:00 2001 From: Diane Wang Date: Tue, 14 May 2024 07:19:30 +0000 Subject: [PATCH 08/14] change to CDROM size Signed-off-by: Diane Wang --- windows/guest_os_inplace_upgrade/mount_upgrade_to_iso.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/windows/guest_os_inplace_upgrade/mount_upgrade_to_iso.yml b/windows/guest_os_inplace_upgrade/mount_upgrade_to_iso.yml index 00aaa1b8b..056cbe133 100644 --- a/windows/guest_os_inplace_upgrade/mount_upgrade_to_iso.yml +++ b/windows/guest_os_inplace_upgrade/mount_upgrade_to_iso.yml @@ -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] }}" From ac59bc82c8211d695953a9845f57d3e80f85bfc8 Mon Sep 17 00:00:00 2001 From: Diane Wang Date: Tue, 14 May 2024 07:54:41 +0000 Subject: [PATCH 09/14] fix edition issue Signed-off-by: Diane Wang --- windows/utils/get_windows_system_info.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/windows/utils/get_windows_system_info.yml b/windows/utils/get_windows_system_info.yml index 052fde39a..938428d7a 100644 --- a/windows/utils/get_windows_system_info.yml +++ b/windows/utils/get_windows_system_info.yml @@ -33,10 +33,10 @@ 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') }}" + guest_os_edition_info: "{{ guest_os_ansible_distribution | regex_search('Microsoft 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] }}" + guest_os_edition: "{{ guest_os_edition_info[0].split(' ')[-1] }}" when: guest_os_edition_info and guest_os_edition_info | length > 0 when: guest_os_ansible_distribution From 175448fcbe314dcc9b9af847184b5d444aa71179 Mon Sep 17 00:00:00 2001 From: Diane Wang Date: Wed, 15 May 2024 05:26:15 +0000 Subject: [PATCH 10/14] fix get edition issue Signed-off-by: Diane Wang --- windows/utils/get_windows_system_info.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/windows/utils/get_windows_system_info.yml b/windows/utils/get_windows_system_info.yml index 938428d7a..29601a39b 100644 --- a/windows/utils/get_windows_system_info.yml +++ b/windows/utils/get_windows_system_info.yml @@ -33,10 +33,11 @@ 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( Server)? ([0-9]+) (.*)', '\\3') }}" + guest_os_edition_info: >- + {{ guest_os_ansible_distribution | regex_search('Microsoft Windows( Server)? ([0-9]+) (R2 )?(.*)', '\4') }} - name: "Set fact of Windows guest OS edition info" ansible.builtin.set_fact: - guest_os_edition: "{{ guest_os_edition_info[0].split(' ')[-1] }}" + guest_os_edition: "{{ guest_os_edition_info[0].strip() }}" when: guest_os_edition_info and guest_os_edition_info | length > 0 when: guest_os_ansible_distribution From 15269073c1a9ae8cc4c8a1bd94fbbe90536d192c Mon Sep 17 00:00:00 2001 From: Diane Wang Date: Wed, 15 May 2024 07:45:51 +0000 Subject: [PATCH 11/14] add debug for become Signed-off-by: Diane Wang --- windows/wintools_complete_install_verify/install_vmtools.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/windows/wintools_complete_install_verify/install_vmtools.yml b/windows/wintools_complete_install_verify/install_vmtools.yml index e80f3dfa9..abca7e81c 100755 --- a/windows/wintools_complete_install_verify/install_vmtools.yml +++ b/windows/wintools_complete_install_verify/install_vmtools.yml @@ -29,6 +29,9 @@ ansible.windows.win_shell: "{{ vmtools_install_cmd }}" delegate_to: "{{ vm_guest_ip }}" ignore_errors: true + become: true + become_method: runas + become_user: Administrator register: wintools_install_result async: 600 poll: 0 From aa88857d62012eee4bc44c2aece6803667bb5ed0 Mon Sep 17 00:00:00 2001 From: Diane Wang Date: Thu, 16 May 2024 05:48:02 +0000 Subject: [PATCH 12/14] set become for Windows Server 2012 R2 Signed-off-by: Diane Wang --- .../wintools_complete_install_verify/install_vmtools.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/windows/wintools_complete_install_verify/install_vmtools.yml b/windows/wintools_complete_install_verify/install_vmtools.yml index abca7e81c..38a107d06 100755 --- a/windows/wintools_complete_install_verify/install_vmtools.yml +++ b/windows/wintools_complete_install_verify/install_vmtools.yml @@ -25,13 +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: true + become: "{{ true if ('Windows Server 2012 R2' in guest_os_ansible_distribution) else false }}" become_method: runas - become_user: Administrator + become_user: "{{ 'Administrator' if ('Windows Server 2012 R2' in guest_os_ansible_distribution) else omit }}" register: wintools_install_result async: 600 poll: 0 From a62c8b3280457f500c724f41c0446a761155a6ac Mon Sep 17 00:00:00 2001 From: Diane Wang Date: Fri, 17 May 2024 06:24:23 +0000 Subject: [PATCH 13/14] address comments Signed-off-by: Diane Wang --- windows/utils/get_windows_system_info.yml | 12 +++--------- windows/utils/win_get_driver_installer.yml | 5 ----- 2 files changed, 3 insertions(+), 14 deletions(-) diff --git a/windows/utils/get_windows_system_info.yml b/windows/utils/get_windows_system_info.yml index 29601a39b..17145524b 100644 --- a/windows/utils/get_windows_system_info.yml +++ b/windows/utils/get_windows_system_info.yml @@ -30,15 +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( Server)? ([0-9]+) (R2 )?(.*)', '\4') }} - - name: "Set fact of Windows guest OS edition info" - ansible.builtin.set_fact: - guest_os_edition: "{{ guest_os_edition_info[0].strip() }}" - 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" diff --git a/windows/utils/win_get_driver_installer.yml b/windows/utils/win_get_driver_installer.yml index 3d1b09beb..a54ffcd31 100644 --- a/windows/utils/win_get_driver_installer.yml +++ b/windows/utils/win_get_driver_installer.yml @@ -33,11 +33,6 @@ reg query "HKLM\System\CurrentControlSet\Services\{{ win_driver_service }}" /v 'vwdk.installers' | findstr 'REG' } -# 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' -# } - - name: "Set fact of the driver installer info list" ansible.builtin.set_fact: win_driver_installer_list: "{{ win_powershell_cmd_output.stdout_lines[0].split(' ')[-1] }}" From 939f455ccc96667cdde897573395358c390bb44c Mon Sep 17 00:00:00 2001 From: Diane Wang Date: Fri, 17 May 2024 06:27:34 +0000 Subject: [PATCH 14/14] update become condition Signed-off-by: Diane Wang --- windows/wintools_complete_install_verify/install_vmtools.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/windows/wintools_complete_install_verify/install_vmtools.yml b/windows/wintools_complete_install_verify/install_vmtools.yml index 38a107d06..b75e045e5 100755 --- a/windows/wintools_complete_install_verify/install_vmtools.yml +++ b/windows/wintools_complete_install_verify/install_vmtools.yml @@ -31,7 +31,7 @@ ansible.windows.win_shell: "{{ vmtools_install_cmd }}" delegate_to: "{{ vm_guest_ip }}" ignore_errors: true - become: "{{ true if ('Windows Server 2012 R2' in guest_os_ansible_distribution) else false }}" + 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