From 0b22280f3b1f221d1ed870cdc921b97cbee65c5d Mon Sep 17 00:00:00 2001 From: linhuali Date: Tue, 8 Aug 2023 04:51:16 +0000 Subject: [PATCH] update results.log with rebasing onto #497 Signed-off-by: linhuali --- .../workflows/github-actions-copyright.yml | 4 ++ .../common/dh_get_guest_info.yml | 20 +++++++++- .../common/dh_host_get_guest_ip.yml | 7 ++-- .../dh_host_get_vmtools_version_build.yml | 38 +++++++++++++++++++ .../dh_deploy_vm/deploy_vm_from_iso.yml | 8 +++- plugin/ansible_vsphere_gosv_log.py | 4 +- 6 files changed, 75 insertions(+), 6 deletions(-) create mode 100644 desktop_hypervisor/common/dh_host_get_vmtools_version_build.yml diff --git a/.github/workflows/github-actions-copyright.yml b/.github/workflows/github-actions-copyright.yml index 54821272d..cdf622797 100644 --- a/.github/workflows/github-actions-copyright.yml +++ b/.github/workflows/github-actions-copyright.yml @@ -36,3 +36,7 @@ jobs: windows/**/*.yml linux/vhba_hot_add_remove/*.sh linux/utils/**/*.sh + desktop_hypervisor/**/*.yml + desktop_hypervisor/linux/*.yml + desktop_hypervisor/windows/*.yml + diff --git a/desktop_hypervisor/common/dh_get_guest_info.yml b/desktop_hypervisor/common/dh_get_guest_info.yml index 4b145bd1d..a30f1250b 100644 --- a/desktop_hypervisor/common/dh_get_guest_info.yml +++ b/desktop_hypervisor/common/dh_get_guest_info.yml @@ -11,6 +11,21 @@ become_user: "{{ dh_vm_username }}" when: host_machine_type == "linux" +- name: "Get the detailed data of guest on windows host" + ansible.windows.win_command: + cmd: '"{{ dh_host_vmrun_path }}" -T ws -gu {{ dh_vm_username }} -gp {{ dh_vm_password }} readVariable "{{ dh_vm_vmx_path }}" runtimeConfig guestInfo.detailed.data' + register: vm_guestinfo + delay: 20 + retries: "{{ vm_guestinfo_retry_times | default(10) }}" + until: + - vm_guestinfo is defined + - vm_guestinfo.stdout_lines is defined + - vm_guestinfo.stdout_lines | length != 0 + - "'prettyName' in vm_guestinfo.stdout_lines[0]" + ignore_errors: true + delegate_to: "{{ host_machine_hostname }}" + when: host_machine_type == "windows" + - name: "Initialize guest info variables" ansible.builtin.set_fact: guestinfo_guest_id: '' @@ -23,7 +38,10 @@ - name: "Get guest info retrieved by VMware Tools" ansible.builtin.set_fact: guestinfo_detailed_data: "{{ vm_guestinfo.stdout_lines[0] }}" - guestinfo_vmtools_info: "{{ vmtools_info_from_vmtoolsd }}" + guestinfo_vmtools_info: "{{ vmtools_info_from_vmtoolsd | default('') }}" + guestinfo_guest_id: "{{ dh_vm_guest_id }}" + vm_guest_id: "{{ dh_vm_guest_id }}" + vm_hardware_version: "{{ dh_vm_hardware_version | string }}" guestinfo_gathered: true - name: "Display VM's guest info" diff --git a/desktop_hypervisor/common/dh_host_get_guest_ip.yml b/desktop_hypervisor/common/dh_host_get_guest_ip.yml index c11ec08ab..cf815ab55 100644 --- a/desktop_hypervisor/common/dh_host_get_guest_ip.yml +++ b/desktop_hypervisor/common/dh_host_get_guest_ip.yml @@ -51,12 +51,13 @@ get_ip_status: "{{ lin_get_ip_status }}" when: host_machine_type == "linux" -- name: "Display the get_ip_status result" - ansible.builtin.debug: var=get_ip_status - - name: "Set fact of guest IP" ansible.builtin.set_fact: dh_vm_guest_ip: "{{ get_ip_status.stdout_lines[0] }}" + vm_guest_ip: "{{ get_ip_status.stdout_lines[0] }}" + +- name: "Print VM guest IP address" + ansible.builtin.debug: var=vm_guest_ip - name: "Display VM guest IP address" ansible.builtin.debug: diff --git a/desktop_hypervisor/common/dh_host_get_vmtools_version_build.yml b/desktop_hypervisor/common/dh_host_get_vmtools_version_build.yml new file mode 100644 index 000000000..ea394e5d9 --- /dev/null +++ b/desktop_hypervisor/common/dh_host_get_vmtools_version_build.yml @@ -0,0 +1,38 @@ +# Copyright 2023 VMware, Inc. +# SPDX-License-Identifier: BSD-2-Clause +--- +# Get installed VMware tools version and build number in Windows guest OS +# Return: +# vmtools_version: VMware tools version +# vmtools_build_number: VMware tools build number +# +- name: Initialize VMware tools version info and file path + ansible.builtin.set_fact: + vmtools_info_from_vmtoolsd: '' + vmtools_cmd_path: "C:\\Program Files\\VMware\\VMware Tools\\VMwareToolboxCmd.exe" + vmtools_log_path: "{{ dh_host_download_path }}vmtools.txt" + +- name: "Get vmtools info of guest on windows host" + ansible.windows.win_shell: | + Start-Process -FilePath "{{ dh_host_vmrun_path }}" -ArgumentList '-T ws -gu {{ dh_vm_username }} -gp {{ dh_vm_password }} runScriptInGuest "{{ dh_vm_vmx_path }}" "" "cmd.exe /c \"{{ vmtools_cmd_path }}\" -v > \"{{ vmtools_log_path }}\""' -NoNewWindow + Start-Process -FilePath "{{ dh_host_vmrun_path }}" -ArgumentList '-T ws -gu {{ dh_vm_username }} -gp {{ dh_vm_password }} CopyFileFromGuestToHost "{{ dh_vm_vmx_path }}" "{{ vmtools_log_path }}" "{{ vmtools_log_path }}"' -NoNewWindow + type "{{ vmtools_log_path }}" + register: win_shell_cmd_output + delay: 20 + retries: "{{ win_shell_cmd_retry_times | default(10) }}" + until: + - win_shell_cmd_output is defined + - win_shell_cmd_output.stdout_lines is defined + - win_shell_cmd_output.stdout_lines | length != 0 + - "'build' in win_shell_cmd_output.stdout_lines[0]" + ignore_errors: true + delegate_to: "{{ host_machine_hostname }}" + +- name: Set fact of tools version and build number + ansible.builtin.set_fact: + vmtools_info_from_vmtoolsd: "{{ win_shell_cmd_output.stdout_lines[0] }}" + vmtools_version: "{{ win_shell_cmd_output.stdout_lines[0].split(' ')[0].rsplit('.', 1)[0] }}" + vmtools_build_number: "{{ win_shell_cmd_output.stdout_lines[0].split(' ')[1][1:-1].split('-')[1] }}" + +- name: "Print VMware Tools version and build" + ansible.builtin.debug: var=vmtools_info_from_vmtoolsd \ No newline at end of file diff --git a/desktop_hypervisor/windows/dh_deploy_vm/deploy_vm_from_iso.yml b/desktop_hypervisor/windows/dh_deploy_vm/deploy_vm_from_iso.yml index 8fb6a7bcb..e5c5a2a27 100644 --- a/desktop_hypervisor/windows/dh_deploy_vm/deploy_vm_from_iso.yml +++ b/desktop_hypervisor/windows/dh_deploy_vm/deploy_vm_from_iso.yml @@ -118,4 +118,10 @@ when: dh_vm_firmware | lower == 'efi' - name: "Get Guest VM IP" - include_tasks: ../../common/dh_host_get_guest_ip.yml \ No newline at end of file + include_tasks: ../../common/dh_host_get_guest_ip.yml + +- name: "Get VMTools version" + include_tasks: ../../common/dh_host_get_vmtools_version_build.yml + +- name: "Get VM guest info including detailed data" + include_tasks: ../../common/dh_get_guest_info.yml \ No newline at end of file diff --git a/plugin/ansible_vsphere_gosv_log.py b/plugin/ansible_vsphere_gosv_log.py index eb7acc0a9..a30013453 100644 --- a/plugin/ansible_vsphere_gosv_log.py +++ b/plugin/ansible_vsphere_gosv_log.py @@ -906,6 +906,8 @@ def _collect_ansible_gosv_facts(self, result): "vm_get_vm_info.yml", "vm_upgrade_hardware_version.yml", "vm_get_guest_info.yml", + "dh_get_guest_info.yml", + "dh_host_get_guest_ip.yml", "get_linux_system_info.yml", "get_cloudinit_version.yml", "check_guest_os_gui.yml", @@ -939,7 +941,7 @@ def _collect_ansible_gosv_facts(self, result): if guestinfo_hash not in self.collected_guest_info: self.collected_guest_info[guestinfo_hash] = vm_guest_info - elif (task_file in ["deploy_vm.yml", "test_setup.yml"] and + elif (task_file in ["deploy_vm.yml", "test_setup.yml", "dh_host_get_guest_ip.yml"] and str(task.action) == "ansible.builtin.debug"): if 'var' in task_args and task_args['var'] == "vm_guest_ip": if task_result["vm_guest_ip"]: