Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Linux] Split pre and post tasks out from open-vm-tools installation #569

Merged
merged 3 commits into from
Apr 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 0 additions & 67 deletions linux/open_vm_tools/install_ovt.yml

This file was deleted.

29 changes: 29 additions & 0 deletions linux/open_vm_tools/install_ovt_from_package.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Copyright 2024 VMware, Inc.
# SPDX-License-Identifier: BSD-2-Clause
---
# Install open-vm-tools packages by guest OS package manager
# Parameters
# ovt_packages: open-vm-tools package names
#
# Install open-vm-tools packages
- name: "Install packages {{ ovt_packages }}"
ansible.builtin.command: "{{ package_install_cmd }} {{' '.join(ovt_packages) }}"
register: ovt_install_result
ignore_errors: true
delegate_to: "{{ vm_guest_ip }}"

- name: "Display the packages install output"
ansible.builtin.debug: var=ovt_install_result
when: enable_debug | bool

- name: "Assert command is executed successfully"
ansible.builtin.assert:
that:
- ovt_install_result.stdout is defined
- ovt_install_result.stdout
- ovt_install_result.rc is defined
- ovt_install_result.rc | int == 0
fail_msg: >-
Failed to install open-vm-tools by executing command:
{{ package_install_cmd }} {{' '.join(ovt_packages) }}
Caught error: {{ ovt_install_result.stderr | default('') }}
62 changes: 5 additions & 57 deletions linux/open_vm_tools/ovt_verify_pkg_install.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,66 +17,14 @@
tasks:
- name: "Test case block"
block:
- name: "Test setup"
include_tasks: ../setup/test_setup.yml

- name: "Set update VMware Tools by default"
ansible.builtin.set_fact:
update_vmtools: true
when: update_vmtools is undefined

# Flatcar and RHCOS doesn't support to install open-vm-tools
- name: "Skip test case on {{ guest_os_ansible_distribution }}"
include_tasks: ../../common/skip_test_case.yml
vars:
skip_msg: "Skip test case because {{ guest_os_ansible_distribution }} doesn't support installing open-vm-tools"
skip_reason: "Not Supported"
when: guest_os_ansible_distribution in ['Flatcar', 'RHCOS']

- name: "Skip test case when VM has open-vm-tools installed and update_vmtools is set false"
include_tasks: ../../common/skip_test_case.yml
vars:
skip_msg: "Test case '{{ ansible_play_name }}' is skipped because update_vmtools is set to: {{ update_vmtools }}"
skip_reason: "Skipped"
when: not update_vmtools | bool

- name: "Skip test case when current open-vm-tools is not installed from package"
include_tasks: ../../common/skip_test_case.yml
vars:
skip_msg: >-
Skip test case because current open-vm-tools install type is {{ vmtools_install_type }},
and the uninstall method is unknown.
skip_reason: "Not Applicable"
when:
- vmtools_is_installed
- vmtools_install_type != 'package'

# Initialize variables
- name: "Set fact whether to uninstall open-vm-tools packages"
ansible.builtin.set_fact:
uninstall_tools: "{{ vmtools_is_installed }}"

- name: "Set facts of open-vm-tools packages, processes and service"
include_tasks: ../utils/set_ovt_facts.yml

- name: "Set facts of VGAuthService process and service"
include_tasks: ../utils/set_vgauth_facts.yml

- name: "Get OS commands to uninstall or install open-vm-tools"
include_tasks: get_install_uninstall_cmd.yml

- name: "Uninstall open-vm-tools for reinstall"
include_tasks: uninstall_ovt.yml
when: uninstall_tools | bool
- name: "Prepare for installing open-vm-tools"
include_tasks: pre_ovt_install.yml

- name: "Install open-vm-tools packages"
include_tasks: install_ovt.yml

- name: "Refresh VM guest info"
include_tasks: ../../common/vm_get_guest_info.yml
include_tasks: install_ovt_from_package.yml

- name: "Take a new snapshot and set it as base snapshot"
include_tasks: ../../common/reset_base_snapshot.yml
- name: "Post actions after open-vm-tools installation"
include_tasks: post_ovt_install.yml
rescue:
- name: "Test case failure"
include_tasks: ../../common/test_rescue.yml
Expand Down
29 changes: 29 additions & 0 deletions linux/open_vm_tools/post_ovt_install.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Copyright 2024 VMware, Inc.
# SPDX-License-Identifier: BSD-2-Clause
---
#
- name: "Eject CDROM device from guest OS"
include_tasks: ../utils/eject_cdrom_in_guest.yml
when:
- enable_local_dvd_repo is defined
- enable_local_dvd_repo | bool

- name: "Reboot guest OS"
include_tasks: ../utils/reboot.yml

- name: "Wait for VMware Tools running"
include_tasks: ../../common/vm_wait_vmtools_status.yml
vars:
vm_wait_vmtools_running: true

- name: "Get guest OS IP after reboot"
include_tasks: ../../common/update_inventory.yml

- name: "Get VMware Tools version and build"
include_tasks: ../utils/get_guest_ovt_version_build.yml

- name: "Update VM guest info after installing open-vm-tools"
include_tasks: ../../common/vm_get_guest_info.yml

- name: "Take a new snapshot and set it as base snapshot"
include_tasks: ../../common/reset_base_snapshot.yml
93 changes: 93 additions & 0 deletions linux/open_vm_tools/pre_ovt_install.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
# Copyright 2024 VMware, Inc.
# SPDX-License-Identifier: BSD-2-Clause
---
#
- name: "Set fact to update VMware Tools by default"
ansible.builtin.set_fact:
update_vmtools: true
when: update_vmtools is undefined

- name: "Test setup"
include_tasks: ../setup/test_setup.yml

- name: "Skip test case because VM has open-vm-tools installed and update_vmtools is false"
include_tasks: ../../common/skip_test_case.yml
vars:
skip_msg: "Test case '{{ ansible_play_name }}' is skipped because VM has open-vm-tools and update_vmtools is set to: {{ update_vmtools }}"
skip_reason: "Skipped"
when:
- vmtools_is_installed
- not update_vmtools

# Flatcar and RHCOS doesn't support to install open-vm-tools
- name: "Skip test case for {{ guest_os_ansible_distribution }}"
include_tasks: ../../common/skip_test_case.yml
vars:
skip_msg: "Skip test case {{ ansible_play_name }} because {{ guest_os_ansible_distribution }} doesn't support installing open-vm-tools"
skip_reason: "Not Supported"
when: guest_os_ansible_distribution in ['Flatcar', 'RHCOS']

- name: "Skip test case when current open-vm-tools is not installed from package"
include_tasks: ../../common/skip_test_case.yml
vars:
skip_msg: >-
Skip test case because current open-vm-tools install type is {{ vmtools_install_type }},
and the uninstall method is unknown.
skip_reason: "Not Applicable"
when:
- vmtools_is_installed
- vmtools_install_type != 'package'

- name: "Initialize fact whether to uninstall open-vm-tools"
ansible.builtin.set_fact:
uninstall_tools: "{{ vmtools_is_installed }}"

- name: "Set facts of open-vm-tools packages, processes and service"
include_tasks: ../utils/set_ovt_facts.yml

- name: "Set facts of VGAuthService process and service"
include_tasks: ../utils/set_vgauth_facts.yml

- name: "Get OS commands to uninstall or install open-vm-tools"
include_tasks: get_install_uninstall_cmd.yml

- name: "Uninstall open-vm-tools packages for reinstall"
include_tasks: uninstall_ovt.yml
when: uninstall_tools | bool

# Add package repositories
# Always add online package repositories for CentOS/VMware Photon OS/Debian
- name: "Add online package repositories for {{ guest_os_ansible_distribution }}"
include_tasks: ../utils/add_official_online_repo.yml
when: guest_os_ansible_distribution in ['CentOS', 'VMware Photon OS', 'Debian']

# Add local DVD repository or online repository for installing OS bundled open-vm-tools
- name: "Add package repositories for {{ guest_os_ansible_distribution }}"
when: linux_ovt_repo_url is undefined or not linux_ovt_repo_url
block:
- name: "Set fact of enabling local DVD repository"
ansible.builtin.set_fact:
enable_local_dvd_repo: >-
{{
guest_os_ansible_distribution in ['SLES', 'SLED', 'RedHat', 'Rocky',
'AlmaLinux', 'openSUSE Leap']
}}

- name: "Add a local package repository from ISO image for {{ guest_os_ansible_distribution }}"
include_tasks: ../utils/add_local_dvd_repo.yml
when: enable_local_dvd_repo | bool

- name: "Add online package repositories for {{ guest_os_ansible_distribution }}"
include_tasks: ../utils/add_official_online_repo.yml
when: guest_os_ansible_distribution in ['OracleLinux', 'Ubuntu']

# Add an extra online repository for install not-bundled open-vm-tools
- name: "Add an extra open-vm-tools repository from URL"
include_tasks: ../utils/add_extra_online_repo.yml
vars:
extra_repo_name: "open-vm-tools-repo"
extra_repo_baseurl: "{{ linux_ovt_repo_url }}"
when: linux_ovt_repo_url is defined and linux_ovt_repo_url

- name: "Update package metadata"
include_tasks: ../utils/repo_update.yml