Skip to content

Commit

Permalink
fix some logic
Browse files Browse the repository at this point in the history
Signed-off-by: Yanan Shen <yanans@vmware.com>
  • Loading branch information
123lzxm committed Dec 26, 2023
1 parent d870145 commit 1f814f1
Showing 1 changed file with 25 additions and 20 deletions.
45 changes: 25 additions & 20 deletions windows/windows_update_install/windows_update_install.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# This case is to test Microsoft's Windows updates.
# Install Windows .msu update package.
#
- name: windows_update
- name: windows_update_install
hosts: localhost
gather_facts: no
tasks:
Expand Down Expand Up @@ -50,17 +50,17 @@
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] }}"
when:
- win_powershell_cmd_output.stdout_lines is defined
- win_powershell_cmd_output.stdout_lines | length != 0

- name: "Failed to copy the msu file to {{ msu_file_dest_path }}"
ansible.builtin.fail:
fail_msg: "The msu file is not found in {{ msu_file_dest_path }}."
when: msu_file_name

- name: "Set the msu file installation related parameters"
ansible.builtin.set_fact:
Expand Down Expand Up @@ -139,15 +139,20 @@
vars:
exit_testing_when_fail: true
always:
- name: "Check if the msu file exists in guest OS"
include_tasks: ../utils/win_check_file_exist.yml
vars:
win_check_file_exist_file: "{{ msu_file_dest }}"

- name: "Delete the msu file from guest OS"
ansible.windows.win_file:
path: "{{ msu_file_dest }}"
state: absent
delegate_to: "{{ vm_guest_ip }}"
register: delete_file_result
when: win_check_file_exist_result
when:
- msu_file_dest is defined
- msu_file_dest
block:
- name: "Check if the msu file exists in guest OS"
include_tasks: ../utils/win_check_file_exist.yml
vars:
win_check_file_exist_file: "{{ msu_file_dest }}"

- name: "Delete the msu file from guest OS"
ansible.windows.win_file:
path: "{{ msu_file_dest }}"
state: absent
delegate_to: "{{ vm_guest_ip }}"
register: delete_file_result
when: win_check_file_exist_result

0 comments on commit 1f814f1

Please sign in to comment.