Skip to content

Commit 16fd822

Browse files
committed
[Linux] Get installed open-vm-tools packages before uninstalling
Signed-off-by: Qi Zhang <[email protected]>
1 parent 16a6ad1 commit 16fd822

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

linux/open_vm_tools/uninstall_ovt.yml

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,26 @@
55
# Parameters:
66
# ovt_packages: a list of open-vm-tools packages
77
#
8+
9+
- name: "Get installed packages on {{ vm_guest_os_distribution }}"
10+
include_tasks: ../utils/get_installed_packages.yml
11+
12+
- name: "Set fact of installed open-vm-tools related packages"
13+
ansible.builtin.set_fact:
14+
installed_ovt_packages: "{{ ovt_packages | select('in', guest_installed_packages) }}"
15+
16+
- name: "Display open-vm-tools related packages which are installed in guest OS"
17+
ansible.builtin.debug: var=installed_ovt_packages
18+
819
# Uninstall open-vm-tools packages
9-
- name: "Uninstall packages {{ ovt_packages }}"
10-
ansible.builtin.command: "{{ package_uninstall_cmd }} {{ ' '.join(ovt_packages) }}"
20+
- name: "Uninstall open-vm-tools related packages on {{ vm_guest_os_distribution }}"
21+
ansible.builtin.command: "{{ package_uninstall_cmd }} {{ ' '.join(installed_ovt_packages) }}"
1122
register: ovt_uninstall_result
12-
ignore_errors: true
1323
delegate_to: "{{ vm_guest_ip }}"
1424

1525
- name: "Display the packages uninstall output"
1626
ansible.builtin.debug: var=ovt_uninstall_result
17-
when: enable_debug | bool
18-
19-
- name: "Assert command is executed successfully"
20-
ansible.builtin.assert:
21-
that:
22-
- ovt_uninstall_result is defined
23-
- ovt_uninstall_result.stdout is defined
24-
- ovt_uninstall_result.stdout
25-
- ovt_uninstall_result.rc is defined
26-
- ovt_uninstall_result.rc | int == 0
27-
fail_msg: "Failed to uninstall open-vm-tools by executing command: {{ package_uninstall_cmd }} {{ ' '.join(ovt_packages) }}"
27+
when: enable_debug
2828

2929
- name: "Reboot VM to make changes take effect"
3030
include_tasks: ../utils/reboot.yml
@@ -36,7 +36,7 @@
3636
include_tasks: check_ovt_package.yml
3737
vars:
3838
expected_package_state: "absent"
39-
with_items: "{{ ovt_packages }}"
39+
with_items: "{{ installed_ovt_packages }}"
4040
loop_control:
4141
loop_var: package_name
4242

0 commit comments

Comments
 (0)