Skip to content

Commit

Permalink
update results.log with rebasing onto vmware#497
Browse files Browse the repository at this point in the history
Signed-off-by: linhuali <[email protected]>
  • Loading branch information
linhuali committed Feb 21, 2024
1 parent 1f13365 commit 5e4915c
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 6 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/github-actions-copyright.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
20 changes: 19 additions & 1 deletion desktop_hypervisor/common/dh_get_guest_info.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: ''
Expand All @@ -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"
Expand Down
7 changes: 4 additions & 3 deletions desktop_hypervisor/common/dh_host_get_guest_ip.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
38 changes: 38 additions & 0 deletions desktop_hypervisor/common/dh_host_get_vmtools_version_build.yml
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -118,4 +118,10 @@
when: dh_vm_firmware | lower == 'efi'

- name: "Get Guest VM IP"
include_tasks: ../../common/dh_host_get_guest_ip.yml
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
4 changes: 3 additions & 1 deletion plugin/ansible_vsphere_gosv_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -910,6 +910,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",
Expand Down Expand Up @@ -943,7 +945,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"]:
Expand Down

0 comments on commit 5e4915c

Please sign in to comment.