Skip to content

Commit

Permalink
address comments
Browse files Browse the repository at this point in the history
Signed-off-by: Yanan Shen <yanans@vmware.com>
  • Loading branch information
123lzxm committed Nov 15, 2023
1 parent ef4826c commit 84428c5
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 41 deletions.
1 change: 1 addition & 0 deletions windows/gosv_testcase_list.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
- import_playbook: wsl_distro_install_uninstall/wsl_distro_install_uninstall.yml
- import_playbook: vbs_enable_disable/vbs_enable_disable.yml
- import_playbook: eflow_deploy/eflow_deploy.yml
- import_playbook: mdag_enable_disable/mdag_enable_disable.yml
- import_playbook: wintools_uninstall_verify/wintools_uninstall_verify.yml
- import_playbook: cpu_hot_add_basic/cpu_hot_add_basic.yml
...
31 changes: 10 additions & 21 deletions windows/guest_customization/win_gosc_prepare.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,34 +63,23 @@
- guest_os_ansible_distribution_ver is version('10.0.22000.0', '>=')
- guest_os_product_type | lower == 'client'

- name: "Initialize BitLocker vars"
ansible.builtin.set_fact:
need_disable_bitlocker: false

- name: "Check if need to disable BitLocker"
block:
- name: "Check if there are encrypted volumes in guest OS"
include_tasks: ../utils/win_get_bitlocker_volume.yml
- name: "Check if there are encrypted volumes in guest OS"
include_tasks: ../utils/win_get_bitlocker_volume.yml

- name: "Get BitLocker service status"
include_tasks: ../utils/win_get_service_status.yml
vars:
win_service_name: "BDESVC"

- name: "Set the value for BitLocker var"
ansible.builtin.set_fact:
need_disable_bitlocker: true
when: >-
(bitlocker_volume_list | length > 0) or
service_status == "Running"
- name: "Get BitLocker service status"
include_tasks: ../utils/win_get_service_status.yml
vars:
win_service_name: "BDESVC"

# Disable BitLocker which will cause sysprep failure.
- name: "Disable Bitlocker"
include_tasks: ../utils/win_disable_bitlocker.yml
when: need_disable_bitlocker | bool
when: >-
(bitlocker_volume_list | length > 0) or
service_status == "Running"
# Shutdown guest OS before execute guest customization
- name: "Shut down OS"
- name: "Shutdown OS"
include_tasks: ../utils/win_shutdown_restart.yml
vars:
set_win_power_state: "shutdown"
25 changes: 10 additions & 15 deletions windows/utils/win_disable_bitlocker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# Disable BitLocker service and decrypt the volumes
# Parameters:
# decrypt_wait_time: the time in seconds to wait for the volume decryption.

#
- name: "Initialize the decryption wait time"
ansible.builtin.set_fact:
decrypt_wait_time: 900
Expand All @@ -15,15 +15,6 @@
vars:
win_powershell_cmd: "Set-Service -Name BDESVC -Status stopped -StartupType disabled"

- name: "Check BitLocker service status"
include_tasks: ../utils/win_get_service_status.yml
vars:
win_service_name: "BDESVC"

- name: "Set BitLocker service status"
ansible.builtin.set_fact:
bitlocker_service_status: "{{ service_status }}"

- name: "Decrypt the BitLocker volumes"
include_tasks: win_execute_cmd.yml
vars:
Expand All @@ -35,6 +26,7 @@
ansible.windows.win_shell: "(Get-BitLockerVolume | Where-Object { $_.EncryptionPercentage -GT 0 } | measure).Count"
register: win_powershell_cmd_output
delegate_to: "{{ vm_guest_ip }}"
ignore_errors: true
until:
- win_powershell_cmd_output.stdout_lines[0] | int == 0
retries: "{{ (decrypt_wait_time | int / 60) | int }}"
Expand All @@ -43,16 +35,19 @@
- name: "Get BitLocker encrypted volumes"
include_tasks: ../utils/win_get_bitlocker_volume.yml

- name: "Check BitLocker service status"
include_tasks: ../utils/win_get_service_status.yml
vars:
win_service_name: "BDESVC"

- name: "Display the bitlocker disablement result"
ansible.builtin.assert:
that:
- bitlocker_service_status == "Stopped"
- service_status == "Stopped"
- bitlocker_volume_list | length == 0
fail_msg: >-
BitLocker is not disabled either due to the service is not stopped or the OS volumes are not decrypted.
BitLocker service status: '{{ bitlocker_service_status }}'.
BitLocker service status: '{{ service_status }}'.
BitLocker encrypted volumes list: '{{ bitlocker_volume_list }}'.
success_msg: >-
BitLocker service is disabled and the OS volumes are decrypted.
BitLocker service is disabled and the OS volumes are decrypted.
9 changes: 4 additions & 5 deletions windows/utils/win_get_bitlocker_volume.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
# Get the volumes encrypted by BitLocker Device Encryption
# Return:
# bitlocker_volume_list: the list of encrypted volume drives

- name: "Initialize the variables"
#
- name: "Initialize the BtiLocker volume list"
ansible.builtin.set_fact:
bitlocker_volume_list: []

Expand All @@ -14,10 +14,9 @@
vars:
win_powershell_cmd: "(Get-BitLockerVolume | Where-Object { $_.EncryptionPercentage -GT 0 }).MountPoint"

- name: "Set bitlocker volume list"
- name: "Set BitLocker volume list"
ansible.builtin.set_fact:
bitlocker_volume_list: "{{ win_powershell_cmd_output.stdout_lines | select }}"
when:
- win_powershell_cmd_output.stdout_lines is defined
- win_powershell_cmd_output.stdout_lines | length != 0

- win_powershell_cmd_output.stdout_lines | length != 0

0 comments on commit 84428c5

Please sign in to comment.