-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
split file windows_update_install.yml
Signed-off-by: Yanan Shen <yanans@vmware.com>
- Loading branch information
Showing
3 changed files
with
119 additions
and
109 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
# Copyright 2023 VMware, Inc. | ||
# SPDX-License-Identifier: BSD-2-Clause | ||
--- | ||
- name: "Set the msu file installation related parameters" | ||
ansible.builtin.set_fact: | ||
msu_kb_number: "{{ msu_file_name | regex_search('(?i)KB\\d+') | upper }}" | ||
msu_file_dest: "{{ msu_file_dest_path }}\\{{msu_file_name }}" | ||
msu_install_timeout: 7200 | ||
msu_become_user: "{{ 'SYSTEM' if guest_os_ansible_architecture == '32-bit' else 'Administrator' }}" | ||
|
||
- name: "Enable the user Administrator" | ||
include_tasks: ../utils/win_execute_cmd.yml | ||
vars: | ||
win_powershell_cmd: "net user Administrator /active:yes" | ||
when: vm_username | lower != "administrator" | ||
|
||
- name: "Install the msu file" | ||
ansible.windows.win_shell: >- | ||
wusa.exe {{ msu_file_dest }} /quiet /norestart | ||
delegate_to: "{{ vm_guest_ip }}" | ||
register: install_msu_result | ||
become: true | ||
become_method: runas | ||
become_user: "{{ msu_become_user }}" | ||
async: "{{ msu_install_timeout }}" | ||
poll: 0 | ||
environment: | ||
ANSIBLE_WIN_ASYNC_STARTUP_TIMEOUT: 10 | ||
|
||
- name: "Check if the msu file is installed before restart" | ||
ansible.windows.win_shell: "Get-HotFix | Where-Object HotFixID -eq {{ msu_kb_number }}" | ||
register: win_get_hotfix_result | ||
ignore_errors: true | ||
delegate_to: "{{ vm_guest_ip }}" | ||
ignore_unreachable: true | ||
until: | ||
- win_get_hotfix_result.rc is defined | ||
- win_get_hotfix_result.rc == 0 | ||
- win_get_hotfix_result.stdout_lines | length != 0 | ||
retries: "{{ msu_install_timeout // 300 }}" | ||
delay: 300 | ||
|
||
- name: "The msu file installation failed" | ||
ansible.builtin.fail: | ||
msg: "Failed to install the msu file in {{ msu_install_timeout }} seconds." | ||
when: | ||
- win_get_hotfix_result.failed is defined | ||
- win_get_hotfix_result.failed | ||
|
||
- name: "Restart guest OS after installing the msu file" | ||
include_tasks: ../utils/win_shutdown_restart.yml | ||
vars: | ||
set_win_power_state: "restart" | ||
win_reboot_timeout: 1800 | ||
|
||
- name: "Check if the msu file is installed after restart" | ||
include_tasks: ../utils/win_execute_cmd.yml | ||
vars: | ||
win_powershell_cmd: "Get-HotFix | Where-Object HotFixID -eq {{ msu_kb_number }}" | ||
|
||
- name: "Check the msu installation result after restart" | ||
ansible.builtin.assert: | ||
that: | ||
- win_powershell_cmd_output.stdout_lines is defined | ||
- win_powershell_cmd_output.stdout_lines | length != 0 | ||
fail_msg: "The msu file {{ msu_kb_number }} is not installed in guest OS." | ||
success_msg: "The msu file {{ msu_kb_number }} is installed in guest OS." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# Copyright 2023 VMware, Inc. | ||
# SPDX-License-Identifier: BSD-2-Clause | ||
--- | ||
- name: "Get unused driver letter" | ||
include_tasks: ../utils/win_get_unused_drive_letter.yml | ||
|
||
- name: "Initialize the msu file path" | ||
ansible.builtin.set_fact: | ||
msu_file_src_path: "{{ drive_letter_new }}:\\{{ windows_update_msu_path }}\\*" | ||
msu_file_dest_path: "C:\\msu" | ||
msu_file_name: "" | ||
|
||
- name: "Check if folder {{ msu_file_dest_path }} exists on guest OS" | ||
include_tasks: ../utils/win_is_folder.yml | ||
vars: | ||
win_is_folder_path: "{{ msu_file_dest_path }}" | ||
|
||
- name: "Create folder {{ msu_file_dest_path }} on guest OS" | ||
include_tasks: ../utils/win_execute_cmd.yml | ||
vars: | ||
win_powershell_cmd: "mkdir {{ msu_file_dest_path }}" | ||
when: not win_is_folder_result | ||
|
||
- name: "Copy the msu file to local disk of guest OS" | ||
include_tasks: ../utils/win_execute_cmd.yml | ||
vars: | ||
win_powershell_cmd: >- | ||
net use {{ drive_letter_new }}: {{ windows_msu_share_point }} {{ windows_nfs_pwd }} /user:{{ windows_nfs_username }}; | ||
Copy-Item -Path {{ msu_file_src_path }} -Include *.msu -Destination {{ msu_file_dest_path }} -ErrorAction Stop; | ||
net use {{ drive_letter_new }}: /delete | ||
- name: "Get the msu file name" | ||
include_tasks: ../utils/win_execute_cmd.yml | ||
vars: | ||
win_powershell_cmd: >- | ||
Get-ChildItem -Path {{ msu_file_dest_path }} -Include *.msu -Name -ErrorAction Stop; | ||
- name: "Check if the msu file is copied to {{ msu_file_dest_path }}" | ||
ansible.builtin.assert: | ||
that: | ||
- win_powershell_cmd_output.stdout_lines is defined | ||
- win_powershell_cmd_output.stdout_lines | length != 0 | ||
fail_msg: "The msu file is not found in {{ msu_file_dest_path }} in guest OS." | ||
success_msg: "The msu file is copied to {{ msu_file_dest_path }} in guest OS." | ||
|
||
- name: "Set the msu file name" | ||
ansible.builtin.set_fact: | ||
msu_file_name: "{{ win_powershell_cmd_output.stdout_lines[0] }}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters