From c2b1aa0561e607f35aaafc5a71fe1a3cd584ddc4 Mon Sep 17 00:00:00 2001 From: Yanan Shen Date: Tue, 9 Jan 2024 16:10:25 +0800 Subject: [PATCH] change word powershell to PowerShell Signed-off-by: Yanan Shen --- changelogs/changelog.yml | 2 +- windows/eflow_deploy/deploy_eflow_vm.yml | 2 +- windows/utils/win_create_vswitch.yml | 10 ++++---- windows/utils/win_enable_client_hyperv.yml | 2 +- windows/utils/win_enable_server_hyperv.yml | 2 +- windows/utils/win_execute_cmd.yml | 2 +- windows/utils/win_get_disk_size.yml | 4 +-- windows/utils/win_get_ethernet_name.yml | 9 ++++--- windows/utils/win_get_set_disk_online.yml | 12 ++++----- windows/utils/win_get_sub_files_folders.yml | 15 ++++++------ windows/utils/win_pause_windows_update.yml | 27 ++++++++++++--------- windows/utils/win_wait_service_status.yml | 4 +-- 12 files changed, 48 insertions(+), 43 deletions(-) diff --git a/changelogs/changelog.yml b/changelogs/changelog.yml index d0a607017..882383de5 100644 --- a/changelogs/changelog.yml +++ b/changelogs/changelog.yml @@ -90,7 +90,7 @@ releases: - Ignore the result check for getting process vmmemmdag. - Fix issue of "guest_os_family" undefined. - Fix deployment failure of ubuntu 20.04.6 desktop VM with bios firmware. - - Save the powershell result before using it in when condition. + - Save the PowerShell result before using it in when condition. - Fix waiting IPv4 address failure when hw_eth0.ipaddresses is null. - Fix the issue that PVRDMA client VM has same IP address with server VM. - Fix variable 'boot_disk_label' undefined issue in test case "nvdimm_cold_add_remove". diff --git a/windows/eflow_deploy/deploy_eflow_vm.yml b/windows/eflow_deploy/deploy_eflow_vm.yml index 0a39a59b6..6fb892a4d 100644 --- a/windows/eflow_deploy/deploy_eflow_vm.yml +++ b/windows/eflow_deploy/deploy_eflow_vm.yml @@ -134,4 +134,4 @@ - not win_powershell_cmd_output.failed - win_powershell_cmd_output.stdout is defined - "'failed' not in win_powershell_cmd_output.stdout" - fail_msg: "Deploy EFLOW virtual machine task failed or there is 'failed' keyword found in the output, please check the failure in above powershell command result." + fail_msg: "Deploy EFLOW virtual machine task failed or there is 'failed' keyword found in the output, please check the failure in above PowerShell command result." diff --git a/windows/utils/win_create_vswitch.yml b/windows/utils/win_create_vswitch.yml index f21325d0c..84dea2985 100644 --- a/windows/utils/win_create_vswitch.yml +++ b/windows/utils/win_create_vswitch.yml @@ -26,7 +26,8 @@ - win_vswitch_type in ['Private', 'Internal', 'External'] fail_msg: "Accepted values of parameter 'win_vswitch_type' are 'Private', 'Internal', 'External', while it's set to '{{ win_vswitch_type }}.'" -- name: "Set fact of 'External' virtual switch powershell commands" +- name: "Set fact of 'External' virtual switch PowerShell commands" + when: win_vswitch_type == 'External' block: - name: "Check required parameter for External virtual switch" ansible.builtin.assert: @@ -34,13 +35,12 @@ - win_ethernet_name is defined - win_ethernet_name fail_msg: "Parameter 'win_ethernet_name' is required and set to a valid value when 'win_vswitch_type' is 'External'." - - name: "Set fact of virtual switch powershell commands" + - name: "Set fact of virtual switch PowerShell commands" ansible.builtin.set_fact: win_get_vswitch_cmd: "(Get-VMSwitch -SwitchType {{ win_vswitch_type }} | where-object {$_.Name -eq '{{ win_vswitch_name }}' -and $_.NetAdapterInterfaceDescription -eq '{{ win_ethernet_name }}'} | measure-object).Count" win_create_vswitch_cmd: "New-VMSwitch -name '{{ win_vswitch_name }}' -NetAdapterName '{{ win_ethernet_name }}' -AllowManagementOS $true" - when: win_vswitch_type == 'External' -- name: "Set fact of 'Internal/Private' virtual switch powershell commands" +- name: "Set fact of 'Internal/Private' virtual switch PowerShell commands" ansible.builtin.set_fact: win_get_vswitch_cmd: "(Get-VMSwitch -SwitchType {{ win_vswitch_type }} | where-object {$_.Name -eq '{{ win_vswitch_name }}'} | measure-object).Count" win_create_vswitch_cmd: "New-VMSwitch -name '{{ win_vswitch_name }}' -SwitchType {{ win_vswitch_type }}" @@ -59,6 +59,7 @@ - win_powershell_cmd_output.stdout_lines | length == 1 - name: "vswitch with specified type and name not exist" + when: win_vswitch_exists | int == 0 block: - name: "Create new vswitch" include_tasks: win_execute_cmd.yml @@ -75,7 +76,6 @@ - win_powershell_cmd_output.stdout_lines | length == 1 - win_powershell_cmd_output.stdout_lines[0] | int == 1 fail_msg: "Failed to get new vswitch with name '{{ win_vswitch_name }}' and type '{{ win_vswitch_type }}' after creation: '{{ win_powershell_cmd_output.stdout_lines | default('') }}'" - when: win_vswitch_exists | int == 0 - name: "vswitch with specified type and name exists" debug: diff --git a/windows/utils/win_enable_client_hyperv.yml b/windows/utils/win_enable_client_hyperv.yml index 755d23a10..0713ddcb2 100644 --- a/windows/utils/win_enable_client_hyperv.yml +++ b/windows/utils/win_enable_client_hyperv.yml @@ -3,7 +3,7 @@ --- # Enable Hyper-V feature in Windows Client guest OS. # -- name: "Set fact of Hyper-V powershell commands" +- name: "Set fact of Hyper-V PowerShell commands" ansible.builtin.set_fact: win_enable_hyperv_cmd: "Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V -All -NoRestart -WarningAction SilentlyContinue" win_check_hyperv_cmd: "(Get-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V).State" diff --git a/windows/utils/win_enable_server_hyperv.yml b/windows/utils/win_enable_server_hyperv.yml index 9e791b0ce..7d072b3ec 100644 --- a/windows/utils/win_enable_server_hyperv.yml +++ b/windows/utils/win_enable_server_hyperv.yml @@ -9,7 +9,7 @@ win_hyperv_state: '' win_vmplatform_state: '' -- name: "Set fact of powershell commands" +- name: "Set fact of PowerShell commands" ansible.builtin.set_fact: win_enable_hyperv_cmd: "Install-WindowsFeature -Name Hyper-V -IncludeManagementTools" win_enable_vmplatform_cmd: "Enable-WindowsOptionalFeature -Online -FeatureName VirtualMachinePlatform -All -NoRestart -WarningAction SilentlyContinue" diff --git a/windows/utils/win_execute_cmd.yml b/windows/utils/win_execute_cmd.yml index 9c12c2375..d162dd840 100644 --- a/windows/utils/win_execute_cmd.yml +++ b/windows/utils/win_execute_cmd.yml @@ -50,7 +50,7 @@ - win_powershell_cmd_output.unreachable is defined - win_powershell_cmd_output.unreachable -- name: "Display the PowerShell commmand result" +- name: "Display the PowerShell command result" ansible.builtin.debug: var=win_powershell_cmd_output when: enable_debug no_log: "{{ win_execute_cmd_no_log | default(false) }}" diff --git a/windows/utils/win_get_disk_size.yml b/windows/utils/win_get_disk_size.yml index 3206f7945..a89a2baf0 100644 --- a/windows/utils/win_get_disk_size.yml +++ b/windows/utils/win_get_disk_size.yml @@ -20,12 +20,12 @@ ansible.builtin.set_fact: win_get_disk_size_gb: 0 -- name: "Set powershell command to get size of disk '{{ win_disk_num }}'" +- name: "Set PowerShell command to get size of disk '{{ win_disk_num }}'" ansible.builtin.set_fact: win_cmd_disk_size: "[math]::Round(((Get-Disk -Number {{ win_disk_num | int }}).Size)/1GB)" when: win_disk_num is defined -- name: "Set powershell command to get size of disk '{{ win_disk_uid }}'" +- name: "Set PowerShell command to get size of disk '{{ win_disk_uid }}'" ansible.builtin.set_fact: win_cmd_disk_size: "[math]::Round(((Get-Disk -UniqueId '{{ win_disk_uid }}').Size)/1GB)" when: win_disk_num is undefined and win_disk_uid is defined diff --git a/windows/utils/win_get_ethernet_name.yml b/windows/utils/win_get_ethernet_name.yml index e9d024896..d5c7963ab 100644 --- a/windows/utils/win_get_ethernet_name.yml +++ b/windows/utils/win_get_ethernet_name.yml @@ -5,20 +5,21 @@ # Parameters: # win_get_ethernet_name_mac: the MAC address of network adapter to find # -- name: Get Ethernet name of the network adapter with specified MAC address +- name: "Get Ethernet name of the network adapter with specified MAC address" include_tasks: win_execute_cmd.yml vars: win_powershell_cmd: "(Get-NetAdapter | where-object {$_.MacAddress -eq '{{ win_get_ethernet_name_mac | replace(':','-') }}'}).Name" win_execute_cmd_ignore_error: true -- name: Check powershell command result +- name: "Check PowerShell command result" ansible.builtin.fail: msg: "Not get Ethernet name with specified MAC address: {{ win_get_ethernet_name_mac }}" when: win_powershell_cmd_output.rc != 0 or win_powershell_cmd_output.stdout_lines|length == 0 -- name: Set fact of the Ethernet name +- name: "Set fact of the Ethernet name" ansible.builtin.set_fact: win_get_ethernet_name_result: "{{ win_powershell_cmd_output.stdout_lines[0] }}" when: win_powershell_cmd_output.rc == 0 and win_powershell_cmd_output.stdout_lines|length != 0 -- ansible.builtin.debug: +- name: "Display debug message" + ansible.builtin.debug: msg: "Get Ethernet name of specified MAC address: {{ win_get_ethernet_name_mac }} in guest OS: {{ win_get_ethernet_name_result }}" diff --git a/windows/utils/win_get_set_disk_online.yml b/windows/utils/win_get_set_disk_online.yml index e97f8cd42..2e214ad61 100644 --- a/windows/utils/win_get_set_disk_online.yml +++ b/windows/utils/win_get_set_disk_online.yml @@ -20,28 +20,28 @@ ansible.builtin.set_fact: win_is_disk_online: false -- name: "Set powershell commands to online disk '{{ win_online_disk_num }}'" +- name: "Set PowerShell commands to online disk '{{ win_online_disk_num }}'" ansible.builtin.set_fact: win_cmd_online_disk: "Set-Disk -Number {{ win_online_disk_num | int }} -IsOffline $False" win_cmd_check_disk: "(Get-disk -Number {{ win_online_disk_num | int }}).OperationalStatus" when: win_online_disk_num is defined -- name: "Set powershell commands to online disk '{{ win_online_disk_uid }}'" +- name: "Set PowerShell commands to online disk '{{ win_online_disk_uid }}'" ansible.builtin.set_fact: win_cmd_online_disk: "Set-Disk -UniqueId '{{ win_online_disk_uid }}' -IsOffline $False" win_cmd_check_disk: "(Get-disk -UniqueId '{{ win_online_disk_uid }}').OperationalStatus" when: win_online_disk_num is undefined and win_online_disk_uid is defined -# Set disk to online -- include_tasks: win_execute_cmd.yml +- name: "Set disk to online" + include_tasks: win_execute_cmd.yml vars: win_powershell_cmd: "{{ win_cmd_online_disk }}" when: - win_online_disk_ops is defined - win_online_disk_ops | lower == 'set' -# Get disk online status -- include_tasks: win_execute_cmd.yml +- name: "Get disk online status" + include_tasks: win_execute_cmd.yml vars: win_powershell_cmd: "{{ win_cmd_check_disk }}" - name: "Set fact of the disk online status" diff --git a/windows/utils/win_get_sub_files_folders.yml b/windows/utils/win_get_sub_files_folders.yml index ce29c518c..d52e6ec02 100644 --- a/windows/utils/win_get_sub_files_folders.yml +++ b/windows/utils/win_get_sub_files_folders.yml @@ -7,28 +7,29 @@ # Return: # win_get_files_folders_list # -- ansible.builtin.debug: +- name: "Display debug message" + ansible.builtin.debug: msg: "Specified folder path in guest OS: {{ win_get_files_folders_folder }}" -- name: Initialize the fact of sub folder and file list +- name: "Initialize the fact of sub folder and file list" ansible.builtin.set_fact: win_get_files_folders_list: [] -# Get child items in specified folder -- include_tasks: win_execute_cmd.yml +- name: "Get child items in specified folder" + include_tasks: win_execute_cmd.yml vars: win_powershell_cmd: "(Get-ChildItem -Path '{{ win_get_files_folders_folder }}').Name" win_execute_cmd_ignore_error: true -- name: Get files or folder from powershell output +- name: "Get files or folder from PowerShell output" ansible.builtin.set_fact: win_get_files_folders_list: "{% for item in win_powershell_cmd_output.stdout_lines %}{{ win_get_files_folders_folder }}\\{{ item }} {% endfor %}" when: not win_powershell_cmd_output.failed -- name: Set fact of the files or folder list +- name: "Set fact of the files or folder list" ansible.builtin.set_fact: win_get_files_folders_list: "{{ win_get_files_folders_list.split() }}" when: win_get_files_folders_list | length != 0 -- name: Display the files or folders list +- name: "Display the files or folders list" ansible.builtin.debug: var=win_get_files_folders_list diff --git a/windows/utils/win_pause_windows_update.yml b/windows/utils/win_pause_windows_update.yml index 3f6ef0af0..84a0a033e 100644 --- a/windows/utils/win_pause_windows_update.yml +++ b/windows/utils/win_pause_windows_update.yml @@ -2,32 +2,35 @@ # SPDX-License-Identifier: BSD-2-Clause --- # Windows Update will cause poweroff or restart taking a long time, -# or GOSC test cases failure, so here try to disable auto pdate +# or GOSC test cases failure, so here try to disable auto update # and pause update 7 days. # -# Transfer powershell script to guest OS -- name: Set fact of powershell script file path +# Transfer PowerShell script to guest OS +- name: "Set fact of PowerShell script file path" ansible.builtin.set_fact: local_ps_file: "scripts/pause_windows_update.ps1" remote_ps_file: "C:\\pause_windows_update.ps1" -- include_tasks: win_copy_file_from_local.yml +- name: "Copy file from local to guest OS" + include_tasks: win_copy_file_from_local.yml vars: src_path_local: "{{ local_ps_file }}" dest_path_remote: "C:\\" -- include_tasks: win_check_file_exist.yml +- name: "Check if file exists" + include_tasks: win_check_file_exist.yml vars: win_check_file_exist_file: "{{ remote_ps_file }}" -# Pause Windows update is not a demand task, so ignore errors -- block: - - name: Execute powershell script in guest OS +# Pause Windows Update is not a demand task, so ignore errors +- name: "Execute the PowerShell script to pause Windows Update" + when: + - win_check_file_exist_result is defined + - win_check_file_exist_result | bool + block: + - name: "Execute PowerShell script in guest OS" ansible.windows.win_command: "powershell.exe -ExecutionPolicy bypass -File {{ remote_ps_file }}" delegate_to: "{{ vm_guest_ip }}" ignore_errors: true register: pause_update_result - - name: Display the script execute result + - name: "Display the script execute result" ansible.builtin.debug: var=pause_update_result when: enable_debug - when: - - win_check_file_exist_result is defined - - win_check_file_exist_result | bool diff --git a/windows/utils/win_wait_service_status.yml b/windows/utils/win_wait_service_status.yml index 8851faf1a..3079445ef 100644 --- a/windows/utils/win_wait_service_status.yml +++ b/windows/utils/win_wait_service_status.yml @@ -5,7 +5,7 @@ # Parameters: # win_service_name: the service name # -- name: Check required parameter +- name: "Check required parameter" ansible.builtin.fail: msg: "win_service_name must be defined before get service status" when: win_service_name is undefined or not win_service_name @@ -34,6 +34,6 @@ Windows service '{{ win_service_name }}' status is not running after 50 seconds. Current service status is '{{ get_service_status.stdout_lines[0] | default("") }}'. -- name: Display the powershell command result +- name: "Display the PowerShell command result" ansible.builtin.debug: var=get_service_status when: enable_debug is defined and enable_debug