Skip to content

[Windows] Change to fetching GOSC log files using vm_guest_file_operation.yml in DHCP GOSC #691

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
- 'System32\Sysprep\Panther\setuperr.log'
- 'Panther\setupact.log'
- 'Panther\setuperr.log'
- 'Panther\unattend.xml'
- 'Panther\UnattendGC\setupact.log'
- 'Panther\UnattendGC\setuperr.log'
- 'Debug\NetSetup.LOG'
Expand Down
30 changes: 0 additions & 30 deletions windows/guest_customization/get_gosc_logs_network.yml

This file was deleted.

8 changes: 1 addition & 7 deletions windows/guest_customization/win_gosc_workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,8 @@
- name: "Get VM power state"
include_tasks: ../../common/vm_get_power_state.yml
- name: "Get GOSC log files when VM is power on"
include_tasks: get_gosc_log_files.yml
when: vm_power_state_get == "poweredOn"
block:
- name: "Get GOSC log files in VM with DHCP IP"
include_tasks: get_gosc_logs_network.yml
when: gosc_network_type == "dhcp"
- name: "Get GOSC log files in VM with static IP"
include_tasks: get_gosc_logs_no_network.yml
when: gosc_network_type == "static"
- name: "Revert back VM password"
ansible.builtin.set_fact:
vm_password: "{{ vm_passwd_before_gosc }}"
Expand Down
27 changes: 16 additions & 11 deletions windows/utils/win_check_file_exist.yml
Original file line number Diff line number Diff line change
@@ -1,32 +1,37 @@
# Copyright 2021-2024 VMware, Inc.
# SPDX-License-Identifier: BSD-2-Clause
---
# Check specified file info in Windows guest
# Check if specified file/object exists in Windows guest OS
# Parameters:
# win_check_file_exist_file: the file path
# win_check_file_exist_file: the full path of the file/object to get
# the facts of.
# Return:
# win_check_file_exist_result: true or false
# win_check_file_exist_result: whether the specified file/object exists in
# guest OS or not, returns true or false.
#
- name: Initialize the file status
- name: "Initialize the file status"
ansible.builtin.set_fact:
win_check_file_exist_result: false

- name: Check if specified file exists in Windows guest OS
- name: "Check if specified file exists in Windows guest OS"
ansible.windows.win_stat:
path: "{{ win_check_file_exist_file }}"
delegate_to: "{{ vm_guest_ip }}"
register: win_check_file_info
ignore_errors: true
- name: Display the returned file info

- name: "Display the returned file info"
ansible.builtin.debug: var=win_check_file_info
when: enable_debug is defined and enable_debug
when: enable_debug

- name: Set fact of file existence
- name: "Set fact of file existence"
ansible.builtin.set_fact:
win_check_file_exist_result: true
when:
- "'stat' in win_check_file_info"
- "'exists' in win_check_file_info.stat"
- win_check_file_info.stat is defined
- win_check_file_info.stat.exists is defined
- win_check_file_info.stat.exists
- ansible.builtin.debug:

- name: "Display the check result"
ansible.builtin.debug:
msg: "File '{{ win_check_file_exist_file }}' is in guest OS: {{ win_check_file_exist_result }}"
20 changes: 11 additions & 9 deletions windows/utils/win_get_file.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,19 @@
---
# Get specified file from Windows guest OS to local path
# Parameters:
# win_get_file_src_path: the source path of the file
# win_get_file_dst_path: the destination path of the file
# win_get_file_src_path: the source path of the file in guest OS.
# win_get_file_dst_path: the destination path of the file on local machine.
# win_get_file_ignore_error: whether ignore errors when fetching file,
# default value is false.
#
- name: Get file from Windows guest OS to local
fetch:
- name: "Get file from Windows guest OS to local"
ansible.builtin.fetch:
src: "{{ win_get_file_src_path }}"
dest: "{{ win_get_file_dst_path }}"
register: fetch_file
ignore_errors: true
register: win_fetch_file
ignore_errors: "{{ win_get_file_ignore_error | default(false) }}"
delegate_to: "{{ vm_guest_ip }}"

- name: Display the fetch file result
ansible.builtin.debug: var=fetch_file
when: enable_debug is defined and enable_debug
- name: "Display the result of fetching file"
ansible.builtin.debug: var=win_fetch_file
when: enable_debug
50 changes: 32 additions & 18 deletions windows/utils/win_get_file_folder.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,43 @@
---
# Get specified path from Windows guest OS to local
# Parameters:
# win_get_src_path: the source path
# win_get_dst_path: the destination path
# win_get_src_path: the source file or folder path in guest OS.
# win_get_dst_path: the destination path on local machine.
#
- name: "Set the fact of file path"
- name: "Set facts of the source path and destination path"
ansible.builtin.set_fact:
win_src_path: "{{ win_get_src_path }}"
win_dst_path: "{{ win_get_dst_path }}"

- name: "Check if source path {{ win_src_path }} is a directory"
include_tasks: win_is_folder.yml
- name: "Check if source path '{{ win_src_path }}' exists"
include_tasks: win_check_file_exist.yml
vars:
win_is_folder_path: "{{ win_src_path }}"
win_check_file_exist_file: "{{ win_src_path }}"

- name: "Get specified file from guest OS"
include_tasks: win_get_file.yml
vars:
win_get_file_src_path: "{{ win_src_path }}"
win_get_file_dst_path: "{{ win_dst_path }}"
when: not win_is_folder_result
- name: "Source path '{{ win_src_path }}' not exist in guest OS"
ansible.builtin.debug:
msg: "Skip getting '{{ win_src_path }}' from guest OS to local since it does not exist."
when: not win_check_file_exist_result

- name: "Get files or sub folders in specified folder"
include_tasks: win_get_folder.yml
vars:
win_get_folder_src_path: "{{ win_src_path }}"
win_get_folder_dst_path: "{{ win_dst_path }}"
when: win_is_folder_result
- name: "Source path '{{ win_src_path }}' exists in guest OS"
when: win_check_file_exist_result
block:
- name: "Check if source path '{{ win_src_path }}' is a directory"
include_tasks: win_is_folder.yml
vars:
win_is_folder_path: "{{ win_src_path }}"

- name: "Get specified file from guest OS"
include_tasks: win_get_file.yml
vars:
win_get_file_src_path: "{{ win_src_path }}"
win_get_file_dst_path: "{{ win_dst_path }}"
win_get_file_ignore_error: true
when: not win_is_folder_result

- name: "Get files in specified folder from guest OS recursively"
include_tasks: win_get_folder.yml
vars:
win_get_folder_src_path: "{{ win_src_path }}"
win_get_folder_dst_path: "{{ win_dst_path }}"
when: win_is_folder_result
49 changes: 16 additions & 33 deletions windows/utils/win_get_folder.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,46 +3,29 @@
---
# Get files in a folder recusively from Windows guest OS to local machine
# Parameters:
# win_get_folder_src_path: the source folder in Windows guest OS
# win_get_folder_dst_path: the destination path in local machine
# win_get_folder_src_path: the source folder in Windows guest OS.
# win_get_folder_dst_path: the destination path on local machine.
#
- name: "Display the source folder path"
ansible.builtin.debug: var=win_get_folder_src_path

- name: "Check if source folder exists in guest OS"
include_tasks: win_check_file_exist.yml
- name: "Get files and sub folders list in source folder"
include_tasks: win_get_sub_files_folders.yml
vars:
win_check_file_exist_file: "{{ win_get_folder_src_path }}"
win_get_files_folders_folder: "{{ win_get_folder_src_path }}"

- name: "Set fact of source folder existence state"
ansible.builtin.set_fact:
win_folder_exist: "{{ win_check_file_exist_result }}"

- name: "Get files in source folder from guest OS"
when: win_folder_exist
- name: "Fetch files in source folder from guest OS"
when: win_get_files_folders_list | length != 0
block:
- name: "Get files and sub folders list in source folder"
include_tasks: win_get_sub_files_folders.yml
- name: "Fetch files recusively"
include_tasks: win_get_file_folder.yml
vars:
win_get_files_folders_folder: "{{ win_get_folder_src_path }}"

- name: "Fetch files in source folder from guest OS"
when: win_get_files_folders_list | length != 0
block:
- name: "Fetch files recusively"
include_tasks: win_get_file_folder.yml
vars:
win_get_dst_path: "{{ win_get_folder_dst_path }}"
with_items: "{{ win_get_files_folders_list }}"
loop_control:
loop_var: win_get_src_path

- name: "No files or sub folders in source folder"
ansible.builtin.debug:
msg: "Specified folder is empty in guest OS: {{ win_get_folder_src_path }}, skip getting files."
when: win_get_files_folders_list | length == 0
win_get_dst_path: "{{ win_get_folder_dst_path }}"
with_items: "{{ win_get_files_folders_list }}"
loop_control:
loop_var: win_get_src_path

- name: "Source folder not exist"
- name: "No files or sub folders in source folder"
ansible.builtin.debug:
msg: "Specified folder does not exist in guest OS: {{ win_get_folder_src_path }}, skip getting files."
when: not win_folder_exist
msg: "Specified folder is empty in guest OS: {{ win_get_folder_src_path }}, skip getting files."
when: win_get_files_folders_list | length == 0
18 changes: 10 additions & 8 deletions windows/utils/win_is_folder.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,28 @@
---
# Check if specified path is a directory in Windows guest OS
# Parameters:
# win_is_folder_path: the file path
# win_is_folder_path: the specified path in guest OS.
# Return:
# win_is_folder_result: true or false
# win_is_folder_result: whether the specified path is a directory,
# returns true or false.
#
- name: Initialize the check result
- name: "Initialize the check result"
ansible.builtin.set_fact:
win_is_folder_result: false

# Check if specified path is a directory in Windows guest OS
- include_tasks: win_execute_cmd.yml
- name: "Check if specified path is a directory in Windows guest OS"
include_tasks: win_execute_cmd.yml
vars:
win_powershell_cmd: "(Get-Item -Path '{{ win_is_folder_path }}') -is [System.IO.DirectoryInfo]"
win_execute_cmd_ignore_error: true

- name: Set fact of the check result
- name: "Set fact of the check result"
ansible.builtin.set_fact:
win_is_folder_result: true
when:
- not win_powershell_cmd_output.failed
- win_powershell_cmd_output.stdout_lines | length != 0
- win_powershell_cmd_output.stdout_lines[0] == 'True'
- ansible.builtin.debug:

- name: "Display the check result"
ansible.builtin.debug:
msg: "Specified path in guest OS {{ win_is_folder_path }} is folder: {{ win_is_folder_result }}"