From ebca3b3083de13609eb8bd2c805f215fb7565b63 Mon Sep 17 00:00:00 2001 From: "Qi (Keira) Zhang" Date: Wed, 8 Feb 2023 15:40:26 +0800 Subject: [PATCH] [Linux] Improve check_os_fullname test case to check guest id and guest family (#419) * [Linux] Improve check_os_fullname test case to check guest id and guest family Signed-off-by: Qi Zhang --- common/update_ini_style_file.yml | 2 +- common/vm_get_guest_info.yml | 8 +- common/vm_get_vm_info.yml | 8 +- env_setup/env_setup.yml | 6 + .../check_efi_firmware/check_efi_firmware.yml | 2 +- .../almalinux_fullname_map.yml | 32 ++-- .../check_os_fullname/amazon_fullname_map.yml | 20 +++ .../amazonlinux_fullname_map.yml | 48 ------ .../check_os_fullname/centos_fullname_map.yml | 50 ++---- linux/check_os_fullname/check_os_fullname.yml | 121 ++++++++++----- .../check_os_fullname/debian_fullname_map.yml | 34 ++--- .../oraclelinux_fullname_map.yml | 52 ++----- .../otherlinux_fullname_map.yml | 81 +++++----- .../check_os_fullname/photon_fullname_map.yml | 14 -- linux/check_os_fullname/rhel_fullname_map.yml | 29 ++-- .../check_os_fullname/rocky_fullname_map.yml | 51 +++++-- linux/check_os_fullname/sles_fullname_map.yml | 34 ++--- .../validate_os_fullname.yml | 143 ++++++++++++------ .../check_quiesce_snapshot_custom_script.yml | 2 +- linux/cpu_hot_add_basic/cpu_hot_add_basic.yml | 2 +- .../cpu_multicores_per_socket.yml | 2 +- linux/deploy_vm/collect_vm_logs.yml | 31 ++++ linux/deploy_vm/deploy_vm_from_iso.yml | 21 +-- linux/deploy_vm/deploy_vm_from_ova.yml | 20 +-- .../gosc_cloudinit_dhcp.yml | 2 +- .../gosc_cloudinit_staticip.yml | 2 +- linux/guest_customization/gosc_perl_dhcp.yml | 2 +- .../gosc_perl_staticip.yml | 2 +- .../memory_hot_add_basic.yml | 2 +- linux/stat_balloon/stat_balloon.yml | 2 +- linux/stat_hosttime/stat_hosttime.yml | 2 +- linux/utils/enable_vmtools_logging.yml | 83 ++++++++++ .../vgauth_check_service.yml | 2 +- 33 files changed, 527 insertions(+), 385 deletions(-) create mode 100644 linux/check_os_fullname/amazon_fullname_map.yml delete mode 100644 linux/check_os_fullname/amazonlinux_fullname_map.yml delete mode 100644 linux/check_os_fullname/photon_fullname_map.yml create mode 100644 linux/deploy_vm/collect_vm_logs.yml create mode 100644 linux/utils/enable_vmtools_logging.yml diff --git a/common/update_ini_style_file.yml b/common/update_ini_style_file.yml index 516217199..ddf8a2646 100644 --- a/common/update_ini_style_file.yml +++ b/common/update_ini_style_file.yml @@ -11,7 +11,7 @@ # - name: "Update section {{ section_name }}" - ini_file: + community.general.ini_file: path: "{{ file_path }}" section: "{{ section_name }}" option: "{{ option_name | default(omit) }}" diff --git a/common/vm_get_guest_info.yml b/common/vm_get_guest_info.yml index 0d8eccc49..02606be0e 100644 --- a/common/vm_get_guest_info.yml +++ b/common/vm_get_guest_info.yml @@ -36,9 +36,11 @@ - vm_guestinfo.instance is defined - vm_guestinfo.instance.guest is defined -- ansible.builtin.debug: +- name: "Display VM's guest info" + ansible.builtin.debug: msg: + - "VM guest info VMware tools info: {{ guestinfo_vmtools_info }}" - "VM guest info guest id: {{ guestinfo_guest_id }}" - "VM guest info guest full name: {{ guestinfo_guest_full_name }}" - - "VM guset info guest detailed data: {{ guestinfo_detailed_data }}" - - "VM guest info VMware tools info: {{ guestinfo_vmtools_info }}" + - "VM guest info guest family: {{ guestinfo_guest_family }}" + - "VM guest info guest detailed data: {{ guestinfo_detailed_data }}" diff --git a/common/vm_get_vm_info.yml b/common/vm_get_vm_info.yml index 50ae9c512..881341695 100644 --- a/common/vm_get_vm_info.yml +++ b/common/vm_get_vm_info.yml @@ -4,7 +4,12 @@ # Get VM's vmx file path - include_tasks: vm_get_config.yml vars: - property_list: ['config.files.logDirectory', 'config.files.vmPathName', 'config.guestId', 'config.version'] + property_list: + - 'config.files.logDirectory' + - 'config.files.vmPathName' + - 'config.guestId' + - 'config.guestFullName' + - 'config.version' - name: Set fact of VM path related variables ansible.builtin.set_fact: @@ -14,6 +19,7 @@ vm_vmx_path: "{{ vm_config.config.files.vmPathName | replace('[', '/vmfs/volumes/') | replace('] ', '/') }}" datastore: "{{ vm_config.config.files.logDirectory.split(' ')[0].strip('['']') }}" vm_guest_id: "{{ vm_config.config.guestId }}" + vm_guest_os_version: "{{ vm_config.config.guestFullName }}" vm_hardware_version: "{{ vm_config.config.version }}" vm_hardware_version_num: "{{ vm_config.config.version.split('-')[-1] }}" diff --git a/env_setup/env_setup.yml b/env_setup/env_setup.yml index e0c590cf0..b227cde84 100644 --- a/env_setup/env_setup.yml +++ b/env_setup/env_setup.yml @@ -49,6 +49,12 @@ - include_tasks: ../common/vcenter_get_version_build.yml when: vcenter_is_defined is defined and vcenter_is_defined - include_tasks: ../common/esxi_get_version_build.yml + + - name: "ESXi version {{ esxi_version }} is not supported" + ansible.builtin.fail: + msg: "This project only supports guest OS validation on ESXi 6.5 or later" + when: esxi_version == 'N/A' or esxi_version is version('6.5.0', '<') + # Get ESXi server model info - include_tasks: ../common/esxi_get_model.yml diff --git a/linux/check_efi_firmware/check_efi_firmware.yml b/linux/check_efi_firmware/check_efi_firmware.yml index 9342f8fb8..dcd699ce4 100644 --- a/linux/check_efi_firmware/check_efi_firmware.yml +++ b/linux/check_efi_firmware/check_efi_firmware.yml @@ -3,7 +3,7 @@ --- # Description: # This test case is used for check VM EFI firmware is reported correctly in dmesg -# and in "vmware.log" file, if VM firmware is BIOS, this test case result is 'No Run'. +# and in "vmware.log" file, if VM firmware is BIOS, this test case result is 'Not Applicable'. # - name: check_efi_firmware hosts: localhost diff --git a/linux/check_os_fullname/almalinux_fullname_map.yml b/linux/check_os_fullname/almalinux_fullname_map.yml index 13142dd84..7cb0bfad0 100644 --- a/linux/check_os_fullname/almalinux_fullname_map.yml +++ b/linux/check_os_fullname/almalinux_fullname_map.yml @@ -1,17 +1,29 @@ # Copyright 2022-2023 VMware, Inc. # SPDX-License-Identifier: BSD-2-Clause --- -# Map AlmaLinux when ESXi version > 7.0.3 and VMware Tools version > 11.3.5 -- name: "Set guest_fullname variable for AlmaLinux on ESXi 7.0.3 later and VMTools 11.3.5 later" +# Guest id "almalinux_64Guest and full name "AlmaLinux (64-bit)" is available on ESXi 8.0.0 or later +# Guest full name of AlmaLinux is mapped to "AlmaLinux (64-bit)" when +# VMware Tools version is 12.0.0 or later, ESXi version is 8.0.0 or later. +- name: "Set expected guest id and full name for AlmaLinux with VMware Tools {{ vmtools_version }} on ESXi {{ esxi_version }}" ansible.builtin.set_fact: - guest_fullname: "AlmaLinux ({{ guest_os_bit }})" + expected_guest_id: "almalinux_64Guest" + expected_guest_fullname: "AlmaLinux (64-bit)" when: - - esxi_version is version('7.0.3', '>') - - vmtools_version is version('11.3.5', '>') + - vmtools_version is version('12.0.0', '>=') + - esxi_version is version('8.0.0', '>=') -# Map AlmaLinux when ESXi version <= 7.0.3 or VMware Tools version <= 11.3.5 -- name: "Set guest_fullname variable for AlmaLinux on ESXi 7.0.3 and earlier, or VMTools 11.3.5 and earlier" +# Guest full name of AlmaLinux is mapped to VM's guest OS version when: +# VMware Tools version is 12.0.0 or later, ESXi version is 7.0.3 or earlier. +- name: "Set expected guest id and full name for AlmaLinux with VMware Tools {{ vmtools_version }} on ESXi {{ esxi_version }}" + ansible.builtin.set_fact: + expected_guest_id: "{{ vm_guest_id }}" + expected_guest_fullname: "{{ vm_guest_os_version }}" + when: + - vmtools_version is version('12.0.0', '>=') + - esxi_version is version('8.0.0', '<') + +# Guest full name of AlmaLinux is mapped to "Other N.x Linux (64-bit)" when +# VMware Tools version is 11.3.5 or earlier +- name: "Set expected guest id and full name for AlmaLinux with VMware Tools {{ vmtools_version }} on ESXi {{ esxi_version }}" include_tasks: otherlinux_fullname_map.yml - when: > - esxi_version is version('7.0.3', '<=') or - vmtools_version is version('11.3.5', '<=') + when: vmtools_version is version('12.0.0', '<') diff --git a/linux/check_os_fullname/amazon_fullname_map.yml b/linux/check_os_fullname/amazon_fullname_map.yml new file mode 100644 index 000000000..aa680cbde --- /dev/null +++ b/linux/check_os_fullname/amazon_fullname_map.yml @@ -0,0 +1,20 @@ +# Copyright 2021-2023 VMware, Inc. +# SPDX-License-Identifier: BSD-2-Clause +--- +# Guest id "amazonlinux2_64Guest" and full name "Amazon Linux 2 (64-bit)" is available on ESXi 6.7 U1 or later +# Guest id "amazonlinux3_64Guest" and full name "Amazon Linux 3 (64-bit)" is available on ESXi 7.0.1 or later +- name: "Set fact of expected guest OS major version on ESXi {{ esxi_version }}" + ansible.builtin.set_fact: + expected_guest_major_ver: |- + {%- if (esxi_version is version('6.7.0', '>') and esxi_version is version('7.0.1', '<')) or + (esxi_version is version('6.7.0', '==') and esxi_update_version | int > 0) -%} + {{ [guest_os_ansible_distribution_major_ver | int, 2] | min }} + {%- elif esxi_version is version('7.0.1', '>=') -%} + {{ [guest_os_ansible_distribution_major_ver | int, 3 ] | min }} + {%- endif %} + +- name: "Set expected guest id and full name for Amazon Linux on ESXi {{ esxi_version }}" + ansible.builtin.set_fact: + expected_guest_id: "amazonlinux{{ expected_guest_major_ver }}_64Guest" + expected_guest_fullname: "Amazon Linux {{ expected_guest_major_ver }} (64-bit)" + when: expected_guest_major_ver diff --git a/linux/check_os_fullname/amazonlinux_fullname_map.yml b/linux/check_os_fullname/amazonlinux_fullname_map.yml deleted file mode 100644 index 69958d88b..000000000 --- a/linux/check_os_fullname/amazonlinux_fullname_map.yml +++ /dev/null @@ -1,48 +0,0 @@ -# Copyright 2021-2023 VMware, Inc. -# SPDX-License-Identifier: BSD-2-Clause ---- -# Amazon Linux guestid was overwritten to other3xlinux-64 -# with short-name in /etc/vmware-tools/tools.conf, which will map to "Other 3.x Linux (64-bit)" ( on ESXi 6.7 and later) or -# "Other 3.x or later Linux (64-bit)" (on ESXi 6.5 and earlier) - -- name: "Read /etc/vmware-tools/tools.conf" - ansible.builtin.shell: cat /etc/vmware-tools/tools.conf | grep '^ *short-name *=' - register: result - failed_when: false - changed_when: false - delegate_to: "{{ vm_guest_ip }}" - -- block: - - name: "Initilize shortname" - ansible.builtin.set_fact: - short_name: "{{ result.stdout.split(' = ')[1] }}" - - ansible.builtin.debug: - msg: "Guest short name is overwritten to {{ short_name }}" - when: result.stdout - -# short-name is not in tools.conf -- block: - # Map Amazon Linux when ESXi <= 6.5.0 - - name: "Set guest_fullname variable for Amazon Linux on ESXi <= 6.5.0" - ansible.builtin.set_fact: - guest_fullname: ["Other 3.x or later Linux ({{ guest_os_bit }})", "Other 3.x Linux ({{ guest_os_bit }})"] - when: > - (esxi_version is version('6.5.0', '<=')) or - (esxi_version is version('6.7.0', '==') and (esxi_update_version | int == 0)) - - # Map Amazon Linux when ESXi > 6.7.0 GA - - name: "Set guest_fullname variable for Amazon Linux on ESXi >= 6.7.0" - ansible.builtin.set_fact: - guest_fullname: "Amazon Linux {{ guest_os_ansible_distribution_major_ver }} ({{ guest_os_bit }})" - when: > - (esxi_version is version('6.7.0', '>')) or - (esxi_version is version('6.7.0', '==') and (esxi_update_version | int > 0)) - when: - - short_name is undefined or not short_name - -# short-name = other3xlinux-64 in tools.conf -- name: "Set guest_fullname variable for Amazon Linux on ESXi <= 6.5.0" - ansible.builtin.set_fact: - guest_fullname: ["Other 3.x or later Linux ({{ guest_os_bit }})", "Other 3.x Linux ({{ guest_os_bit }})"] - when: - - short_name is defined and short_name == "other3xlinux-64" diff --git a/linux/check_os_fullname/centos_fullname_map.yml b/linux/check_os_fullname/centos_fullname_map.yml index 4a4bcc6de..2539f8009 100644 --- a/linux/check_os_fullname/centos_fullname_map.yml +++ b/linux/check_os_fullname/centos_fullname_map.yml @@ -1,40 +1,22 @@ # Copyright 2021-2023 VMware, Inc. # SPDX-License-Identifier: BSD-2-Clause --- -# Map CentOS when ESXi < 6.5.0 -- name: Set guest_fullname variable for CentOS on ESXi < 6.5.0 +# Guest id "centos7_64Guest" and full name "CentOS 7 (64-bit)" is available on ESXi 6.5 or later +# Guest id "centos8_64Guest" and full name "CentOS 8 (64-bit)" is available on ESXi 6.7 or later +# Guest id "centos9_64Guest" and full name "CentOS 9 (64-bit)" is available on ESXi 7.0.1 or later +- name: "Set fact of expected guest OS major version on ESXi {{ esxi_version }}" ansible.builtin.set_fact: - guest_fullname: "CentOS 4/5 or later ({{ guest_os_bit }})" - when: esxi_version is version('6.5.0', '<') + expected_guest_major_ver: |- + {%- if esxi_version is version('6.5.0', '>=') and esxi_version is version('6.7.0', '<') -%} + {{ [guest_os_ansible_distribution_major_ver | int, 7 ] | min }} + {%- elif esxi_version is version('6.7.0', '>=') and esxi_version is version('7.0.1', '<') -%} + {{ [guest_os_ansible_distribution_major_ver | int, 8 ] | min }} + {%- elif esxi_version is version('7.0.1', '>=') -%} + {{ [guest_os_ansible_distribution_major_ver | int, 9 ] | min }} + {%- endif %} -# Map CentOS-5 and earlier when ESXi >= 6.5.0 -- name: Set guest_fullname variable for CentOS on ESXi >= 6.5.0 +- name: "Set expected guest id and full name for CentOS on ESXi {{ esxi_version }}" ansible.builtin.set_fact: - guest_fullname: "CentOS {{ guest_os_ansible_distribution_major_ver }} ({{ guest_os_bit }})" - when: - - guest_os_ansible_distribution_major_ver | int <= 5 - - esxi_version is version('6.5.0', '>=') - -# Map CentOS-6, CentOS-7 when ESXi = 6.5.0 -- name: Set guest_fullname variable for CentOS on ESXi = 6.5.0 - ansible.builtin.set_fact: - guest_fullname: "CentOS {{ guest_os_ansible_distribution_major_ver }} ({{ guest_os_bit }})" - when: - - guest_os_ansible_distribution_major_ver | int == 6 or guest_os_ansible_distribution_major_ver | int == 7 - - esxi_version is version('6.5.0', '==') - -# Map CentOS-8 and later when ESXi = 6.5.0 -- name: Set guest_fullname variable for CentOS on ESXi = 6.5.0 - ansible.builtin.set_fact: - guest_fullname: "CentOS 7 ({{ guest_os_bit }})" - when: - - guest_os_ansible_distribution_major_ver | int >= 8 - - esxi_version is version('6.5.0', '==') - -# Map CentOS-6 and later when ESXi >= 6.7.0 -- name: Set guest_fullname variable for CentOS on ESXi >= 6.7.0 - ansible.builtin.set_fact: - guest_fullname: "CentOS {{ guest_os_ansible_distribution_major_ver }} ({{ guest_os_bit }})" - when: - - guest_os_ansible_distribution_major_ver | int >= 6 - - esxi_version is version('6.7.0', '>=') + expected_guest_id: "centos{{ expected_guest_major_ver }}{{ expected_guest_id_suffix }}" + expected_guest_fullname: "CentOS {{ expected_guest_major_ver }} ({{ guest_os_bit }})" + when: expected_guest_major_ver diff --git a/linux/check_os_fullname/check_os_fullname.yml b/linux/check_os_fullname/check_os_fullname.yml index 90816f9d2..d292cb82a 100644 --- a/linux/check_os_fullname/check_os_fullname.yml +++ b/linux/check_os_fullname/check_os_fullname.yml @@ -4,7 +4,7 @@ # Description: # This test case is used for check VM guest OS fullname is reported correctly # in guest info through VMware tools. When VMware tools is not installed or not -# running in VM, this test case result is 'No Run'. +# running in VM, this test case result is 'Blocked'. # - name: check_os_fullname hosts: localhost @@ -14,66 +14,113 @@ tasks: - name: "Test case block" block: - - include_tasks: ../setup/test_setup.yml + - name: "Test setup" + include_tasks: ../setup/test_setup.yml vars: skip_test_no_vmtools: true - # Run this test when VMware tools is running - - include_tasks: ../../common/esxi_get_version_build.yml + - name: "Set VMware Tools debug logging directory" + ansible.builtin.set_fact: + vmtools_log_dir: "/tmp/vmware-tools-{{ lookup('pipe', 'date +%Y%m%d%H%M%S') }}" + + - name: "Enable debug logging for VMware Tools" + include_tasks: ../utils/enable_vmtools_logging.yml + + - name: "Get ESXi version and build" + include_tasks: ../../common/esxi_get_version_build.yml when: esxi_version is undefined or esxi_update_version is undefined - - name: "Get OS fullname in guest OS" + - name: "Display guest OS distribution" ansible.builtin.debug: - msg: "{{ guest_os_ansible_distribution }} {{ guest_os_ansible_distribution_ver }}" + msg: "{{ vm_guest_os_distribution }}" - - name: "Initalize facts for checking guest full name" + - name: "Initialize facts for checking guest id and guest full name" + ansible.builtin.set_fact: + expected_guest_id: "" + expected_guest_id_suffix: "{% if guest_os_bit == '64-bit' %}64{% endif %}Guest" + expected_guest_major_ver: "" + expected_guest_fullname: "" + expected_guest_family: "linuxGuest" + guest_is_otherlinux: true + + - name: "Set fact of guest OS is not other Linux" ansible.builtin.set_fact: - guest_fullname: "guest fullname not defined in test case" guest_is_otherlinux: false + when: >- + guest_os_ansible_distribution in ["RedHat", "CentOS", "OracleLinux", "AlmaLinux", "Rocky", + "SLES", "SLED", "VMware Photon OS", "Amazon", "Fedora", + "Ubuntu", "Debian"] - # Map Ubuntu - - name: "Set guest_fullname variable for Ubuntu" + - name: "Set fact of expected guest id suffix" ansible.builtin.set_fact: - guest_fullname: "Ubuntu Linux ({{ guest_os_bit }})" - when: guest_os_ansible_distribution == "Ubuntu" + expected_guest_id_suffix: "{{ expected_guest_id_suffix | replace('64', '_64') }}" + when: >- + guest_os_ansible_distribution in ["RedHat", "SLES", "SLED", + "CentOS", "OracleLinux", "Debian"] - # Map RHEL full name - - include_tasks: rhel_fullname_map.yml + - name: "Set expected guest id and full name for {{ vm_guest_os_distribution }}" + include_tasks: rhel_fullname_map.yml when: guest_os_ansible_distribution == "RedHat" - # Map SLES full name - - include_tasks: sles_fullname_map.yml + - name: "Set expected guest id and full name for {{ vm_guest_os_distribution }}" + include_tasks: sles_fullname_map.yml when: guest_os_ansible_distribution in ["SLES", "SLED"] - # Map VMware Photon OS guest full name - - include_tasks: photon_fullname_map.yml - when: guest_os_ansible_distribution == "VMware Photon OS" - - - include_tasks: "{{ guest_os_ansible_distribution | lower }}_fullname_map.yml" + - name: "Set expected guest id and full name for {{ vm_guest_os_distribution }}" + include_tasks: "{{ guest_os_ansible_distribution | lower }}_fullname_map.yml" when: guest_os_ansible_distribution in ["Amazon", "CentOS", "OracleLinux", "AlmaLinux", "Rocky", "Debian"] - # Map FreeBSD guest full name - - name: "Set guest_fullname variable for FreeBSD" + - name: "Set expected guest id and full name for {{ vm_guest_os_distribution }}" ansible.builtin.set_fact: - guest_fullname: "FreeBSD {{ guest_os_ansible_distribution_major_ver }} ({{ guest_os_bit }})" - when: guest_os_ansible_distribution == "FreeBSD" + expected_guest_id: "ubuntu{{ expected_guest_id_suffix }}" + expected_guest_fullname: "Ubuntu Linux ({{ guest_os_bit }})" + when: guest_os_ansible_distribution == "Ubuntu" - # Map Fedora - - name: "Set guest_fullname variable for Fedora" + - name: "Set expected guest id and full name for {{ vm_guest_os_distribution }}" ansible.builtin.set_fact: - guest_fullname: "Red Hat Fedora ({{ guest_os_bit }})" - when: guest_os_ansible_distribution == "Fedora" + expected_guest_id: "vmwarePhoton64Guest" + expected_guest_fullname: "VMware Photon OS (64-bit)" + when: guest_os_ansible_distribution == "VMware Photon OS" - # Map Other Linux - - name: "Set fact of the guest is other linux" + - name: "Set expected guest id and full name for {{ vm_guest_os_distribution }}" ansible.builtin.set_fact: - guest_is_otherlinux: true - when: guest_fullname == "guest fullname not defined in test case" + expected_guest_id: "fedora{{ expected_guest_id_suffix }}" + expected_guest_fullname: "Red Hat Fedora ({{ guest_os_bit }})" + when: guest_os_ansible_distribution == "Fedora" - - include_tasks: otherlinux_fullname_map.yml + - name: "Set expected guest id and full name for {{ vm_guest_os_distribution }}" + include_tasks: otherlinux_fullname_map.yml when: guest_is_otherlinux - # Validate guest OS fullname in guestinfo - - include_tasks: validate_os_fullname.yml + - name: "Validate guest OS full name in guestinfo" + include_tasks: validate_os_fullname.yml rescue: - - include_tasks: ../../common/test_rescue.yml + - name: "Test rescue" + include_tasks: ../../common/test_rescue.yml + always: + - name: "Get VMware Tools log directory stat info" + include_tasks: ../utils/get_file_stat_info.yml + vars: + guest_file_path: "{{ vmtools_log_dir }}" + + - name: "Collect VMware Tools logs" + block: + - name: "Archive VMware Tools debug logs" + ansible.builtin.archive: + path: "{{ vmtools_log_dir }}" + dest: "{{ vmtools_log_dir }}.tgz" + mode: "0644" + delegate_to: "{{ vm_guest_ip }}" + register: archive_vmtools_logs + + - name: "Fetch VMware Tools debug logs" + include_tasks: ../utils/fetch_file.yml + vars: + fetch_file_src_path: "{{ vmtools_log_dir }}.tgz" + fetch_file_dst_path: "{{ current_test_log_folder }}/" + fetch_file_ignore_errors: true + when: + - archive_vmtools_logs is defined + - archive_vmtools_logs.changed is defined + - archive_vmtools_logs.changed + when: guest_file_exists diff --git a/linux/check_os_fullname/debian_fullname_map.yml b/linux/check_os_fullname/debian_fullname_map.yml index fbbdcfaa8..debc9947c 100644 --- a/linux/check_os_fullname/debian_fullname_map.yml +++ b/linux/check_os_fullname/debian_fullname_map.yml @@ -1,24 +1,22 @@ # Copyright 2021-2023 VMware, Inc. # SPDX-License-Identifier: BSD-2-Clause --- -# Map Debian when ESXi >= 6.5.0 -- name: "Set guest_fullname variable for Debian on ESXi >= 6.5.0" +# Guest id "debian10_64Guest" and full name "Debian GNU/Linux 10 (64-bit)" is available on ESXi 6.5 or later +# Guest id "debian11_64Guest" and full name "Debian GNU/Linux 11 (64-bit)" is available on ESXi 7.0.0 or later +# Guest id "debian12_64Guest" and full name "Debian GNU/Linux 12 (64-bit)" is available on ESXi 8.0.0 or later +- name: "Set fact of expected guest OS major version on ESXi {{ esxi_version }}" ansible.builtin.set_fact: - guest_fullname: "Debian GNU/Linux {{ guest_os_ansible_distribution_major_ver }} ({{ guest_os_bit }})" - when: esxi_version is version('6.5.0', '>=') + expected_guest_major_ver: |- + {%- if esxi_version is version('6.5.0', '>=') and esxi_version is version('7.0.0', '<') -%} + {{ [guest_os_ansible_distribution_major_ver | int, 10] | min }} + {%- elif esxi_version is version('7.0.0', '>=') and esxi_version is version('8.0.0', '<') -%} + {{ [guest_os_ansible_distribution_major_ver | int, 11 ] | min }} + {%- elif esxi_version is version('8.0.0', '>=') -%} + {{ [guest_os_ansible_distribution_major_ver | int, 12 ] | min }} + {%- endif %} -# Map Debian-9 and later when ESXi < 6.5.0 -- name: "Set guest_fullname variable for Debian on ESXi < 6.5.0" +- name: "Set expected guest id and full name for Debian on ESXi {{ esxi_version }}" ansible.builtin.set_fact: - guest_fullname: "Debian GNU/Linux 8 ({{ guest_os_bit }})" - when: - - guest_os_ansible_distribution_major_ver | int >= 9 - - esxi_version is version('6.5.0', '<') - -# Map Debian-8 and earlier when ESXi < 6.5.0 -- name: "Set guest_fullname variable for Debian on ESXi < 6.5.0" - ansible.builtin.set_fact: - guest_fullname: "Debian GNU/Linux {{ guest_os_ansible_distribution_major_ver }} ({{ guest_os_bit }})" - when: - - guest_os_ansible_distribution_major_ver | int < 9 - - esxi_version is version('6.5.0', '<') + expected_guest_id: "debian{{ expected_guest_major_ver }}{{ expected_guest_id_suffix }}" + expected_guest_fullname: "Debian GNU/Linux {{ expected_guest_major_ver }} ({{ guest_os_bit }})" + when: expected_guest_major_ver diff --git a/linux/check_os_fullname/oraclelinux_fullname_map.yml b/linux/check_os_fullname/oraclelinux_fullname_map.yml index 4ad19d92a..95fb4acb1 100644 --- a/linux/check_os_fullname/oraclelinux_fullname_map.yml +++ b/linux/check_os_fullname/oraclelinux_fullname_map.yml @@ -1,42 +1,22 @@ # Copyright 2021-2023 VMware, Inc. # SPDX-License-Identifier: BSD-2-Clause --- -# Map Oracle Linux on ESXi < 6.5.0 -- name: "Set guest_fullname variable for Oracle Linux {{ guest_os_ansible_distribution_major_ver }} on ESXi {{ esxi_version }}" +# Guest id "oraclelinux7_64Guest" and full name "Oracle Linux 7 (64-bit)" is available on ESXi 6.5 or later +# Guest id "oraclelinux8_64Guest" and full name "Oracle Linux 8 (64-bit)" is available on ESXi 6.7 or later +# Guest id "oraclelinux9_64Guest" and full name "Oracle Linux 9 (64-bit)" is available on ESXi 7.0.1 or later +- name: "Set fact of expected guest OS major version on ESXi {{ esxi_version }}" ansible.builtin.set_fact: - guest_fullname: "Oracle Linux 4/5 or later ({{ guest_os_bit }})" - when: esxi_version is version('6.5.0', '<') + expected_guest_major_ver: |- + {%- if esxi_version is version('6.5.0', '>=') and esxi_version is version('6.7.0', '<') -%} + {{ [guest_os_ansible_distribution_major_ver | int, 7 ] | min }} + {%- elif esxi_version is version('6.7.0', '>=') and esxi_version is version('7.0.1', '<') -%} + {{ [guest_os_ansible_distribution_major_ver | int, 8 ] | min }} + {%- elif esxi_version is version('7.0.1', '>=') -%} + {{ [guest_os_ansible_distribution_major_ver | int, 9 ] | min }} + {%- endif %} -# Map Oracle Linux 5 and earlier on ESXi >= 6.5.0 -- name: "Set guest_fullname variable for Oracle Linux {{ guest_os_ansible_distribution_major_ver }} on ESXi {{ esxi_version }}" +- name: "Set expected_guest_fullname for Oracle Linux {{ guest_os_ansible_distribution_major_ver }} on ESXi {{ esxi_version }}" ansible.builtin.set_fact: - guest_fullname: "Oracle Linux 4/5 ({{ guest_os_bit }})" - when: - - guest_os_ansible_distribution_major_ver | int <= 5 - - esxi_version is version('6.5.0', '>=') - -# Map Oracle Linux 6 and later on ESXi 6.5 -- name: "Set guest_fullname variable for Oracle Linux {{ guest_os_ansible_distribution_major_ver }} on ESXi {{ esxi_version }}" - ansible.builtin.set_fact: - guest_fullname: "Oracle Linux {{ [guest_os_ansible_distribution_major_ver | int, 7 ] | min }} ({{ guest_os_bit }})" - when: - - guest_os_ansible_distribution_major_ver | int >= 6 - - esxi_version is version('6.5.0', '>=') - - esxi_version is version('6.7.0', '<') - -# Map Oracle Linux 6 and later on ESXi 6.7 and 7.0.0 -- name: "Set guest_fullname variable for Oracle Linux {{ guest_os_ansible_distribution_major_ver }} on ESXi {{ esxi_version }}" - ansible.builtin.set_fact: - guest_fullname: "Oracle Linux {{ [guest_os_ansible_distribution_major_ver | int, 8 ] | min }} ({{ guest_os_bit }})" - when: - - guest_os_ansible_distribution_major_ver | int >= 6 - - esxi_version is version('6.7.0', '>=') - - esxi_version is version('7.0.0', '<=') - -# Map Oracle linux 6 and later on ESXi 7.0.1 and later -- name: "Set guest_fullname variable for Oracle Linux {{ guest_os_ansible_distribution_major_ver }} on ESXi {{ esxi_version }}" - ansible.builtin.set_fact: - guest_fullname: "Oracle Linux {{ [guest_os_ansible_distribution_major_ver | int, 9] | min }} ({{ guest_os_bit }})" - when: - - guest_os_ansible_distribution_major_ver | int >= 6 - - esxi_version is version('7.0.1', '>=') + expected_guest_id: "oracleLinux{{ expected_guest_major_ver }}{{ expected_guest_id_suffix }}" + expected_guest_fullname: "Oracle Linux {{ expected_guest_major_ver }} ({{ guest_os_bit }})" + when: expected_guest_major_ver diff --git a/linux/check_os_fullname/otherlinux_fullname_map.yml b/linux/check_os_fullname/otherlinux_fullname_map.yml index 10b57df91..6d393ef90 100644 --- a/linux/check_os_fullname/otherlinux_fullname_map.yml +++ b/linux/check_os_fullname/otherlinux_fullname_map.yml @@ -1,55 +1,46 @@ # Copyright 2021-2023 VMware, Inc. # SPDX-License-Identifier: BSD-2-Clause --- -# Map Flatcar, RockyLinux, or other Linux distribution which doesn't have a unique guest id - -# If there is no best match of the guest full name on ESXi server, it will show the guest OS detailed information -# in the guest full name, which include the kernel version and os distribution -- name: "Set unmapped guest fullname for {{ guest_os_ansible_distribution }} {{ guest_os_ansible_distribution_ver }} on ESXi 6.7GA" +- name: "Set fact of Linux kernel major version" ansible.builtin.set_fact: - unmapped_os_fullname: "Linux {{ guest_os_ansible_kernel }} {{ guest_os_ansible_distribution }}" - -# Linux 5.x -- block: - # Map Linux 5.x when ESXi <= 7.0.0 - - block: - - name: "Set guest_fullname variable for {{ guest_os_ansible_distribution }} {{ guest_os_ansible_distribution_ver }} on ESXi <= 7.0.0" - ansible.builtin.set_fact: - guest_fullname: ["Other 3.x or later Linux ({{ guest_os_bit }})", "Other 3.x Linux ({{ guest_os_bit }})"] - when: "'other3xLinux' in vm_guest_id" + linux_kernel_major_ver: "{{ guest_os_ansible_kernel | regex_search('^\\d+') }}" - - name: "Set guest_fullname variable for {{ guest_os_ansible_distribution }} {{ guest_os_ansible_distribution_ver }} on ESXi <= 7.0.0" - ansible.builtin.set_fact: - guest_fullname: ["Other 4.x or later Linux ({{ guest_os_bit }})", "Other 4.x Linux ({{ guest_os_bit }})"] - when: "'other4xLinux' in vm_guest_id" - when: esxi_version is version('7.0.0', '<=') +- name: "Fail the test due to unknown Linux kernel major version" + ansible.builtin.fail: + msg: "Failed to extract major version from Linux kernel version {{ guest_os_ansible_kernel }}" + when: not linux_kernel_major_ver - # Map Linux 5.x when ESXi > 7.0.0 as Other 5.x or later Linux is supported on ESXi 7.0.1 and later - - name: "Set guest_fullname variable for {{ guest_os_ansible_distribution }} {{ guest_os_ansible_distribution_ver }} on ESXi > 7.0.0" - ansible.builtin.set_fact: - guest_fullname: ["Other 5.x or later Linux ({{ guest_os_bit }})", "Other 5.x Linux ({{ guest_os_bit }})"] - when: esxi_version is version('7.0.0', '>') - when: guest_os_ansible_kernel is version('5.0', '>=') +# Linux kernel >= 5.x +- name: "Set expected_guest_id and expected_guest_fullname with VM's guest OS version on ESXi {{ esxi_version }}" + ansible.builtin.set_fact: + expected_guest_id: "{{ vm_guest_id }}" + expected_guest_fullname: "{{ vm_guest_os_version }}" + when: + - linux_kernel_major_ver | int >= 5 + - esxi_version is version('7.0.0', '<=') -# Linux 4.x -- block: - - name: "Set guest_fullname variable for {{ guest_os_ansible_distribution }} {{ guest_os_ansible_distribution_ver }} on ESXi <= 7.0.0" +# Guest id "other3xlinux64Guest" and full name "Other 3.x (or later) Linux (64-bit)" is available on ESXi 5.5 or later +# Guest id "other4xlinux64Guest" and full name "Other 4.x (or later) Linux (64-bit)" is available on ESXi 6.7 or later +# Guest id "other5xlinux45Guest" and full name "Other 5.x (or later) Linux (64-bit)" is available on ESXi 7.0.1 or later +# Guest id "other6xlinux46Guest" and full name "Other 6.x (or later) Linux (64-bit)" is available on ESXi 8.0.0 or later +- name: "Set expected_guest_id and expected_guest_fullname on ESXi {{ esxi_version }}" + block: + - name: "Set fact of expected guest OS major version on ESXi {{ esxi_version }}" ansible.builtin.set_fact: - guest_fullname: ["Other 3.x or later Linux ({{ guest_os_bit }})", "Other 3.x Linux ({{ guest_os_bit }})"] - when: esxi_version is version('6.7.0', '<') + expected_guest_major_ver: |- + {%- if esxi_version is version('6.7.0', '<') -%} + {{ [linux_kernel_major_ver | int, 3] | min }} + {%- elif esxi_version is version('6.7.0', '>=') and esxi_version is version('7.0.1', '<') -%} + {{ [linux_kernel_major_ver | int, 4 ] | min }} + {%- elif esxi_version is version('7.0.1', '>=') and esxi_version is version('8.0.0', '<') -%} + {{ [linux_kernel_major_ver | int, 5 ] | min }} + {%- elif esxi_version is version('8.0.0', '>=') -%} + {{ [linux_kernel_major_ver | int, 6 ] | min }} + {%- endif %} - - name: "Set guest_fullname variable for {{ guest_os_ansible_distribution }} {{ guest_os_ansible_distribution_ver }}" + - name: "Set expected_guest_id and expected_guest_fullname for {{ vm_guest_os_distribution }} on ESXi {{ esxi_version }}" ansible.builtin.set_fact: - guest_fullname: ["Other 4.x or later Linux ({{ guest_os_bit }})", "Other 4.x Linux ({{ guest_os_bit }})"] - when: esxi_version is version('6.7.0', '>=') - when: - - guest_os_ansible_kernel is version('5.0', '<') - - guest_os_ansible_kernel is version('4.0', '>=') - -# Linux 3.x -- name: "Set guest_fullname variable for {{ guest_os_ansible_distribution }} {{ guest_os_ansible_distribution_ver }}" - ansible.builtin.set_fact: - guest_fullname: ["Other 3.x or later Linux ({{ guest_os_bit }})", "Other 3.x Linux ({{ guest_os_bit }})"] - when: - - guest_os_ansible_kernel is version('4.0', '<') - - guest_os_ansible_kernel is version('3.0', '>=') + expected_guest_id: "other{{ expected_guest_major_ver }}xLinux{{ expected_guest_id_suffix }}" + expected_guest_fullname: "Other {{ expected_guest_major_ver }}.x or later Linux ({{ guest_os_bit }})" + when: expected_guest_major_ver + when: linux_kernel_major_ver | int < 5 or esxi_version is version('7.0.0', '>') diff --git a/linux/check_os_fullname/photon_fullname_map.yml b/linux/check_os_fullname/photon_fullname_map.yml deleted file mode 100644 index 8b4fa50bf..000000000 --- a/linux/check_os_fullname/photon_fullname_map.yml +++ /dev/null @@ -1,14 +0,0 @@ -# Copyright 2021-2023 VMware, Inc. -# SPDX-License-Identifier: BSD-2-Clause ---- -# Map VMware Photon OS when HW >= 13 -- name: "Set guest_fullname variable for Photon on ESXi >= 6.5.0" - ansible.builtin.set_fact: - guest_fullname: "VMware Photon OS ({{ guest_os_bit }})" - when: esxi_version is version('6.5.0', '>=') - -# Map VMware Photon OS when HW < 13 -- name: "Set guest_fullname variable for Photon on ESXi < 6.5.0" - ansible.builtin.set_fact: - guest_fullname: "Other 3.x or later Linux ({{ guest_os_bit }})" - when: esxi_version is version('6.5.0', '<') diff --git a/linux/check_os_fullname/rhel_fullname_map.yml b/linux/check_os_fullname/rhel_fullname_map.yml index c32f4057d..70816dbcc 100644 --- a/linux/check_os_fullname/rhel_fullname_map.yml +++ b/linux/check_os_fullname/rhel_fullname_map.yml @@ -1,19 +1,22 @@ # Copyright 2021-2023 VMware, Inc. # SPDX-License-Identifier: BSD-2-Clause --- -- name: "Set guest_fullname variable for RHEL {{ guest_os_ansible_distribution_major_ver }} on ESXi < 6.7.0" +# Guest id "rhel7_64Guest" and full name "Red Hat Enterprise Linux 7 (64-bit)" is available on ESXi 5.1 or later +# Guest id "rhel8_64Guest" and full name "Red Hat Enterprise Linux 8 (64-bit)" is available on ESXi 6.7 or later +# Guest id "rhel9_64Guest" and full name "Red Hat Enterprise Linux 9 (64-bit)" is available on ESXi 7.0.1 or later +- name: "Set fact of expected guest OS major version on ESXi {{ esxi_version }}" ansible.builtin.set_fact: - guest_fullname: "Red Hat Enterprise Linux {{ [guest_os_ansible_distribution_major_ver | int, 7] | min }} ({{ guest_os_bit }})" - when: esxi_version is version('6.7.0', '<') + expected_guest_major_ver: |- + {%- if esxi_version is version('6.7.0', '<') -%} + {{ [guest_os_ansible_distribution_major_ver | int, 7] | min }} + {%- elif esxi_version is version('6.7.0', '>=') and esxi_version is version('7.0.1', '<') -%} + {{ [guest_os_ansible_distribution_major_ver | int, 8] | min }} + {%- elif esxi_version is version('7.0.1', '>=') -%} + {{ [guest_os_ansible_distribution_major_ver | int, 9 ] | min }} + {%- endif %} -- name: "Set guest_fullname variable for RHEL {{ guest_os_ansible_distribution_major_ver }} on ESXi >= 6.7.0 and ESXi <= 7.0.0" +- name: "Set expected guest id and full name for {{ vm_guest_os_distribution }} on ESXi {{ esxi_version }}" ansible.builtin.set_fact: - guest_fullname: "Red Hat Enterprise Linux {{ [guest_os_ansible_distribution_major_ver | int, 8] | min }} ({{ guest_os_bit }})" - when: - - esxi_version is version('6.7.0', '>=') - - esxi_version is version('7.0.0', '<=') - -- name: "Set guest_fullname variable for RHEL {{ guest_os_ansible_distribution_major_ver }} on ESXi >= 7.0.1" - ansible.builtin.set_fact: - guest_fullname: "Red Hat Enterprise Linux {{ [guest_os_ansible_distribution_major_ver | int, 9] | min }} ({{ guest_os_bit }})" - when: esxi_version is version('7.0.1', '>=') + expected_guest_id: "rhel{{ expected_guest_major_ver }}{{ expected_guest_id_suffix }}" + expected_guest_fullname: "Red Hat Enterprise Linux {{ expected_guest_major_ver }} ({{ guest_os_bit }})" + when: expected_guest_major_ver diff --git a/linux/check_os_fullname/rocky_fullname_map.yml b/linux/check_os_fullname/rocky_fullname_map.yml index c059c81df..1524c16e4 100644 --- a/linux/check_os_fullname/rocky_fullname_map.yml +++ b/linux/check_os_fullname/rocky_fullname_map.yml @@ -1,18 +1,49 @@ # Copyright 2022-2023 VMware, Inc. # SPDX-License-Identifier: BSD-2-Clause --- -# Map Rocky Linux when ESXi version > 7.0.3 and VMware Tools version >= 12.0.0 -- name: "Set guest_fullname variable for Rocky Linux on ESXi 7.0.3 later and VMTools 12.0.0 or later" +# Guest id "rockylinux_64Guest and full name "Rocky Linux (64-bit)" is available on ESXi 8.0.0 or later +# Guest fullname of Rocky Linux is mapped to "Rocky Linux (64-bit)" when +# VMware Tools version is 12.0.0 or later, ESXi version is 8.0.0 or later +- name: "Set expected guest id and full name for Rocky Linux with VMware Tools {{ vmtools_version }} on ESXi {{ esxi_version }}" ansible.builtin.set_fact: - guest_fullname: "Rocky Linux ({{ guest_os_bit }})" + expected_guest_id: "rockylinux_64Guest" + expected_guest_fullname: "Rocky Linux (64-bit)" when: - - esxi_version is version('7.0.3', '>') - vmtools_version is version('12.0.0', '>=') + - esxi_version is version('8.0.0', '>=') -# Map Rocky Linux when ESXi version <= 7.0.3 or VMware Tools version < 12.0.0 -- name: "Set guest_fullname variable for Rocky Linux on ESXi 7.0.3 and earlier, or VMTools 12.0.0 earlier" - include_tasks: otherlinux_fullname_map.yml - when: > - esxi_version is version('7.0.3', '<=') or - vmtools_version is version('12.0.0', '<') +# Guest fullname of Rocky Linux is mapped VM's guest OS version when: +# VMware Tools version is 12.0.0 or later, ESXi version is 7.0.3 or earlier. +- name: "Set expected guest id and full name for Rocky Linux with VMware Tools {{ vmtools_version }} on ESXi {{ esxi_version }}" + ansible.builtin.set_fact: + expected_guest_id: "{{ vm_guest_id }}" + expected_guest_fullname: "{{ vm_guest_os_version }}" + when: + - vmtools_version is version('12.0.0', '>=') + - esxi_version is version('8.0.0', '<') + +- name: "Set expected guest id and full name for Rocky Linux with VMware Tools {{ vmtools_version }}" + block: + - name: "Get open-vm-tools package info" + include_tasks: ../utils/get_installed_package_info.yml + vars: + package_name: "open-vm-tools" + + - name: "Set fact whether open-vm-tools vendor is Rocky Linux" + ansible.builtin.set_fact: + ovt_vendor_is_rocky: "{{ package_info.Vendor | default('') is search('Rocky') }}" + + # Guest fullname of Rocky Linux is mapped VM's guest OS version when: + # VMware Tools version is 11.3.5 or earlier, and open-vm-tools package vendor is Rocky Linux + - name: "Set expected guest id and full name for Rocky Linux with VMware Tools {{ vmtools_version }}" + ansible.builtin.set_fact: + expected_guest_id: "{{ vm_guest_id }}" + expected_guest_fullname: "{{ vm_guest_os_version }}" + when: ovt_vendor_is_rocky + # Guest fullname of Rocky Linux is mapped to Other N.x Linux (64-bit) when: + # VMware Tools version is 11.3.5 or earlier, and open-vm-tools package vendor is not Rocky Linux + - name: "Set expected guest id and full name for Rocky Linux with VMware Tools {{ vmtools_version }}" + include_tasks: otherlinux_fullname_map.yml + when: not ovt_vendor_is_rocky + when: vmtools_version is version('12.0.0', '<') diff --git a/linux/check_os_fullname/sles_fullname_map.yml b/linux/check_os_fullname/sles_fullname_map.yml index ea9ac8f61..342babfca 100644 --- a/linux/check_os_fullname/sles_fullname_map.yml +++ b/linux/check_os_fullname/sles_fullname_map.yml @@ -1,24 +1,22 @@ # Copyright 2021-2023 VMware, Inc. # SPDX-License-Identifier: BSD-2-Clause --- -# Map SLES when ESXi >= 14 -- name: Set guest_fullname variable for SLES on ESXi >= 6.7.0 +# Guest id "sles12_64Guest" and full name "SUSE Linux Enterprise 12 (64-bit)" is available on ESXi 5.1 or later +# Guest id "sles15_64Guest" and full name "SUSE Linux Enterprise 15 (64-bit)" is available on ESXi 6.7 or later +# Guest id "sles16_64Guest" and full name "SUSE Linux Enterprise 16 (64-bit)" is available on ESXi 7.0.1 or later +- name: "Set fact of expected guest OS major version on ESXi {{ esxi_version }}" ansible.builtin.set_fact: - guest_fullname: "SUSE Linux Enterprise {{ guest_os_ansible_distribution_major_ver }} ({{ guest_os_bit }})" - when: esxi_version is version('6.7.0', '>=') + expected_guest_major_ver: |- + {%- if esxi_version is version('6.7.0', '<') -%} + {{ [guest_os_ansible_distribution_major_ver | int, 12] | min }} + {%- elif esxi_version is version('6.7.0', '>=') and esxi_version is version('7.0.1', '<') -%} + {{ [guest_os_ansible_distribution_major_ver | int, 15] | min }} + {%- elif esxi_version is version('7.0.1', '>=') -%} + {{ [guest_os_ansible_distribution_major_ver | int, 16 ] | min }} + {%- endif %} -# Map SLES-12 and earlier when ESXi <= 6.5.0 -- name: Set guest_fullname variable for SLES-12 and earlier on ESXi <= 6.5.0 +- name: "Set expected guest id and full name for {{ vm_guest_os_distribution }} on ESXi {{ esxi_version }}" ansible.builtin.set_fact: - guest_fullname: "SUSE Linux Enterprise {{ guest_os_ansible_distribution_major_ver }} ({{ guest_os_bit }})" - when: - - guest_os_ansible_distribution_major_ver | int <= 12 - - esxi_version is version('6.5.0', '<=') - -# Map SLES-15 when ESXi <= 6.5.0 -- name: Set guest_fullname variable for SLES-15 on ESXi <= 6.5.0 - ansible.builtin.set_fact: - guest_fullname: "SUSE Linux Enterprise 12 ({{ guest_os_bit }})" - when: - - guest_os_ansible_distribution_major_ver | int == 15 - - esxi_version is version('6.5.0', '<=') + expected_guest_id: "sles{{ expected_guest_major_ver }}{{ expected_guest_id_suffix }}" + expected_guest_fullname: "SUSE Linux Enterprise {{ expected_guest_major_ver }} ({{ guest_os_bit }})" + when: expected_guest_major_ver diff --git a/linux/check_os_fullname/validate_os_fullname.yml b/linux/check_os_fullname/validate_os_fullname.yml index 3dd0fd0d8..153924ef5 100644 --- a/linux/check_os_fullname/validate_os_fullname.yml +++ b/linux/check_os_fullname/validate_os_fullname.yml @@ -1,63 +1,108 @@ # Copyright 2021-2023 VMware, Inc. # SPDX-License-Identifier: BSD-2-Clause --- -# Wait VMware tools to report Guest OS fullname -- include_tasks: ../../common/vm_get_guest_info.yml +- name: "Check expected guest id and full name is set for {{ vm_guest_os_distribution }}" + ansible.builtin.assert: + that: + - expected_guest_id + - expected_guest_fullname + fail_msg: >- + Failed to set expected guest id or guest full name for {{ vm_guest_os_distribution }} + with VMware Tools {{ vmtools_version }} on ESXi {{ esxi_version }} server. + +- name: "Get VM's guest info" + include_tasks: ../../common/vm_get_guest_info.yml -# If the guest os full name is unmapped and displays OS detailed data, test passed -- block: - - name: "guest OS detailed information is shown in guest OS full name, test passed" - ansible.builtin.meta: end_host +- name: "Display ESXi version and VM's hardware version" + ansible.builtin.debug: + msg: + - "ESXi version: {{ esxi_version }}" + - "VM's hardware version: {{ vm_hardware_version }}" + +# If the guest os full name is unmapped and displays OS detailed data on ESXi 6.7 GA and Update 1, +# or on ESXi 7.0.0, that's expected. Test passed. +- name: "Check unmapped guest OS full name on ESXi {{ esxi_version }} when guest id is empty" + block: + # The unmapped guest full name which at least includes Linux kernel version, OS pretty name + # For VM with newer VMware Tools, the unmapped guest full name also includes OS name, version id and build id + # Here we only check linux kernel version and OS pretty name + - name: "Set unmapped guest full name for {{ vm_guest_os_distribution }} on ESXi {{ esxi_version }}" + ansible.builtin.set_fact: + unmapped_guest_fullname: "Linux {{ guest_os_ansible_kernel }} {{ guest_os_release.PRETTY_NAME }}" + when: guest_os_release.PRETTY_NAME | default('') + + - name: "Test passed" + block: + - name: "Guest OS full name is unmapped" + ansible.builtin.debug: + msg: >- + Guest id is '{{ guestinfo_guest_id }}' on ESXi {{ esxi_version }}, and + guest OS full name is '{{ guestinfo_guest_full_name }}', which shows + guest OS detailed information and is as expected on ESXi {{ esxi_version }}. + Test Passed. + tags: + - known_issue + - name: "Test passed on ESXi {{ esxi_version }}" + ansible.builtin.meta: end_host + when: + - unmapped_guest_fullname is defined and unmapped_guest_fullname + - unmapped_guest_fullname in guestinfo_guest_full_name when: - - (esxi_version is version('6.7.0', '==') and (esxi_update_version | int < 2)) or (esxi_version is version('7.0.0', '==')) - - unmapped_os_fullname is defined and unmapped_os_fullname - - unmapped_os_fullname in guestinfo_guest_full_name + - not guestinfo_guest_id + - ((esxi_version is version('6.7.0', '==') and + esxi_update_version | int < 2) or + esxi_version is version('7.0.0', '==')) -- name: "Check guest ID in guest info is not empty" +- name: "Check guest id in VM's guest info with VMware Tools {{ vmtools_version }} on ESXi {{ esxi_version }}" ansible.builtin.assert: that: - - guestinfo_guest_id - fail_msg: "Guest ID in guest info is '{{ guestinfo_guest_id }}', which should be a valid value firstly." + - guestinfo_guest_id == expected_guest_id + fail_msg: >- + VM's guest id in guest info is '{{ guestinfo_guest_id }}', + not expected '{{ expected_guest_id }}'. + success_msg: >- + VM's guest id in guest info is '{{ guestinfo_guest_id }}', + which is as expected '{{ expected_guest_id }}'. -- name: "Known issue about Rocky Linux guest fullname" +- name: "Check guest full name in VM's guest info with VMware Tools {{ vmtools_version }} on ESXi {{ esxi_version }}" + ansible.builtin.assert: + that: + - guestinfo_guest_full_name == expected_guest_fullname + fail_msg: >- + VM's guest full name is '{{ guestinfo_guest_full_name }}', + not expected '{{ expected_guest_fullname }}'. + success_msg: >- + VM's guest full name is '{{ guestinfo_guest_full_name }}', + which is as expected '{{ expected_guest_fullname }}'. + when: not (expected_guest_fullname is match('Other \\d+.x .*Linux.*')) + +- name: "Check guest full name in VM's guest info" block: - - include_tasks: ../utils/get_installed_package_info.yml - vars: - package_name: "open-vm-tools" - - - name: "Known issue - ignore incorrect guest fullname with Rocky Linux built-in OVT 11.3.5" - ansible.builtin.debug: - msg: - - "The guest fullname of Rocky Linux with built-in open-vm-tools 11.3.5-{{ package_info.Release }} is always same as VM's guest OS version." - - "The expected guest fullname should be {{ ', or '.join(guest_fullname) }}. Ignore this known issue." - - "Please refer to https://bugs.rockylinux.org/view.php?id=200" - tags: - - known_issue - when: - - package_info is defined - - package_info.Release is defined - - package_info.Release == "1.el8" or package_info.Release == "1.el9" - - package_info.Vendor is defined and 'Rocky' in package_info.Vendor - when: - - guest_os_ansible_distribution == 'Rocky' - - vmtools_version is version('11.3.5', '=') + - name: "Set alternative for the expected guest full name" + ansible.builtin.set_fact: + expected_guest_fullname_alternative: "{{ expected_guest_fullname | replace('or later ', '') }}" -- block: - - name: "Assert Guest OS fullname is either {{ guest_fullname[0] }} or {{ guest_fullname[1] }}" + - name: "Check guest full name in VM's guest info with VMware Tools {{ vmtools_version }} on ESXi {{ esxi_version }}" ansible.builtin.assert: that: - - guestinfo_guest_full_name in guest_fullname - fail_msg: > - "VM '{{ vm_name }}' guest OS fullname is: '{{ guestinfo_guest_full_name }}', - not expected '{{ guest_fullname[0] }}' or '{{ guest_fullname[1] }}'" - when: - - guest_fullname is sequence - - guest_fullname | length == 2 + - guestinfo_guest_full_name in [expected_guest_fullname, expected_guest_fullname_alternative] + fail_msg: >- + VM's guest full name is '{{ guestinfo_guest_full_name }}', + not expected '{{ expected_guest_fullname }}' + or '{{ expected_guest_fullname_alternative }}'. + success_msg: >- + VM's guest full name is '{{ guestinfo_guest_full_name }}', + which is as expected '{{ expected_guest_fullname }}' + or '{{ expected_guest_fullname_alternative }}'. + when: expected_guest_fullname is match('Other \\d+.x .*Linux.*') -- block: - - name: "Assert Guest OS fullname is {{ guest_fullname }}" - ansible.builtin.assert: - that: - - guestinfo_guest_full_name == guest_fullname - fail_msg: "VM '{{ vm_name }}' guest OS fullname is: '{{ guestinfo_guest_full_name }}', not expected '{{ guest_fullname }}'" - when: guest_fullname is string +- name: "Check guest family in VM's guest info with VMware Tools {{ vmtools_version }} on ESXi {{ esxi_version }}" + ansible.builtin.assert: + that: + - guestinfo_guest_family == expected_guest_family + fail_msg: >- + VM's guest family in guest info is '{{ guestinfo_guest_family }}', + not expected '{{ expected_guest_family }}'. + success_msg: >- + VM's guest family in guest info is '{{ guestinfo_guest_family }}', + which is as expected '{{ expected_guest_family }}'. diff --git a/linux/check_quiesce_snapshot_custom_script/check_quiesce_snapshot_custom_script.yml b/linux/check_quiesce_snapshot_custom_script/check_quiesce_snapshot_custom_script.yml index 29911e19c..9c2a3f206 100644 --- a/linux/check_quiesce_snapshot_custom_script/check_quiesce_snapshot_custom_script.yml +++ b/linux/check_quiesce_snapshot_custom_script/check_quiesce_snapshot_custom_script.yml @@ -3,7 +3,7 @@ --- # Description: # This test case is used for check taking quiesce snapshot on VM through VMware tools. -# When VMware tools is not installed or not running in VM, this test case result is 'No Run'. +# When VMware tools is not installed or not running in VM, this test case result is "Blocked". # - name: check_quiesce_snapshot_custom_script hosts: localhost diff --git a/linux/cpu_hot_add_basic/cpu_hot_add_basic.yml b/linux/cpu_hot_add_basic/cpu_hot_add_basic.yml index 54bc45487..8435f3494 100644 --- a/linux/cpu_hot_add_basic/cpu_hot_add_basic.yml +++ b/linux/cpu_hot_add_basic/cpu_hot_add_basic.yml @@ -5,7 +5,7 @@ # This test case is used for check VM vCPU hotadd works as expected. # When calculated vCPU hotadd number list from ESXi server CPU number # and configured maximum CPU number (default 16) is empty, this test -# case result is 'No Run'. +# case result is 'Blocked'. # Note: VM vCPU number will be set to 2, cores per socket will be set # to 1 before vCPU hotadd test. # diff --git a/linux/cpu_multicores_per_socket/cpu_multicores_per_socket.yml b/linux/cpu_multicores_per_socket/cpu_multicores_per_socket.yml index 53925a515..e60b53177 100644 --- a/linux/cpu_multicores_per_socket/cpu_multicores_per_socket.yml +++ b/linux/cpu_multicores_per_socket/cpu_multicores_per_socket.yml @@ -5,7 +5,7 @@ # This test case is used for test multiple cores per socket configuration # of VM vCPU. When calculated vCPU number list from ESXi server CPU number # and configured maximum CPU number (default 16) is empty, this test case -# result is 'No Run'. +# result is 'Blocked'. # Note: VM vCPU number will be set to 2, cores per socket will be set to 1 # before multiple cores test. # diff --git a/linux/deploy_vm/collect_vm_logs.yml b/linux/deploy_vm/collect_vm_logs.yml new file mode 100644 index 000000000..16e8fe89c --- /dev/null +++ b/linux/deploy_vm/collect_vm_logs.yml @@ -0,0 +1,31 @@ +# Copyright 2023 VMware, Inc. +# SPDX-License-Identifier: BSD-2-Clause +--- +# Collect cloud-init logs for deploying Ubuntu live-server, +# cloud image or Photon OVA. +# +- name: "Collect VM logs" + block: + - name: "Get VM's power state" + include_tasks: ../../common/vm_get_power_state.yml + + - name: "Collect cloud-init logs" + block: + - name: "Get VM's guest info" + include_tasks: ../../common/vm_get_guest_info.yml + + - name: "Collect cloud-init logs" + include_tasks: ../utils/collect_cloudinit_logs.yml + when: + - guestinfo_guest_id is defined + - ((guestinfo_guest_id is match('ubuntu.*') and + unattend_install_conf is defined and + unattend_install_conf is match('Ubuntu/Server/')) or + (ova_guest_os_type is defined and + ova_guest_os_type in ['photon', 'ubuntu'])) + when: + - vm_power_state_get is defined + - vm_power_state_get == "poweredOn" + when: + - vm_exists is defined + - vm_exists diff --git a/linux/deploy_vm/deploy_vm_from_iso.yml b/linux/deploy_vm/deploy_vm_from_iso.yml index 59cd64651..f6457a0af 100644 --- a/linux/deploy_vm/deploy_vm_from_iso.yml +++ b/linux/deploy_vm/deploy_vm_from_iso.yml @@ -294,24 +294,9 @@ - ol9_uekr7_is_upgraded rescue: - # Collect cloud-init logs for Ubuntu - - include_tasks: ../../common/vm_get_power_state.yml - - name: "Collect cloud-innit logs" - block: - - include_tasks: ../../common/vm_get_vmtools_status.yml - vars: - get_vmtools_status_retries: 10 - - include_tasks: ../utils/collect_cloudinit_logs.yml - when: - - vmtools_is_installed is defined - - vmtools_is_installed - - vmtools_is_running is defined - - vmtools_is_running - when: - - vm_power_state_get is defined - - vm_power_state_get == "poweredOn" - - unattend_install_conf is match('Ubuntu') - - include_tasks: ../../common/test_rescue.yml vars: exit_testing_when_fail: true + always: + - name: "Collect VM deployment logs" + include_tasks: collect_vm_logs.yml diff --git a/linux/deploy_vm/deploy_vm_from_ova.yml b/linux/deploy_vm/deploy_vm_from_ova.yml index f5624c724..2c359aa20 100644 --- a/linux/deploy_vm/deploy_vm_from_ova.yml +++ b/linux/deploy_vm/deploy_vm_from_ova.yml @@ -138,21 +138,5 @@ del_local_file_ignore_errors: true when: nfs_mount_dir is defined and nfs_mount_dir - # Collect cloud-init logs for deploying Ubuntu and Photon OVA - - include_tasks: ../../common/vm_get_power_state.yml - - name: "Collect cloud-init logs" - block: - - include_tasks: ../../common/vm_get_vmtools_status.yml - vars: - get_vmtools_status_retries: 10 - - include_tasks: ../utils/collect_cloudinit_logs.yml - when: - - vmtools_is_installed is defined - - vmtools_is_installed - - vmtools_is_running is defined - - vmtools_is_running - when: - - vm_power_state_get is defined - - vm_power_state_get == "poweredOn" - - ova_guest_os_type is defined - - ova_guest_os_type in ['photon', 'ubuntu'] + - name: "Collect VM deployment logs" + include_tasks: collect_vm_logs.yml diff --git a/linux/guest_customization/gosc_cloudinit_dhcp.yml b/linux/guest_customization/gosc_cloudinit_dhcp.yml index fde939130..8b0f14542 100644 --- a/linux/guest_customization/gosc_cloudinit_dhcp.yml +++ b/linux/guest_customization/gosc_cloudinit_dhcp.yml @@ -4,7 +4,7 @@ # Description: # This test case is used for check cloud-init guest customization # with VM DHCP network configuration. If VMware tools is not installed -# or not running, this test case result is "No Run". +# or not running, this test case result is "Blocked". # - name: gosc_cloudinit_dhcp hosts: localhost diff --git a/linux/guest_customization/gosc_cloudinit_staticip.yml b/linux/guest_customization/gosc_cloudinit_staticip.yml index 35554b333..70e9c5f81 100644 --- a/linux/guest_customization/gosc_cloudinit_staticip.yml +++ b/linux/guest_customization/gosc_cloudinit_staticip.yml @@ -4,7 +4,7 @@ # Description: # This test case is used for check cloud-init guest customization # with VM static network configuration. If VMware tools is not installed -# or not running, this test case result is "No Run". +# or not running, this test case result is "Blocked". # - name: gosc_cloudinit_staticip hosts: localhost diff --git a/linux/guest_customization/gosc_perl_dhcp.yml b/linux/guest_customization/gosc_perl_dhcp.yml index 9ed23dfbb..15a3e3f72 100644 --- a/linux/guest_customization/gosc_perl_dhcp.yml +++ b/linux/guest_customization/gosc_perl_dhcp.yml @@ -4,7 +4,7 @@ # Description: # This test case is used for check traditional perl guest customization # with VM DHCP network configuration. If VMware tools is not installed -# or not running, this test case result is "No Run". +# or not running, this test case result is "Blocked". # - name: gosc_perl_dhcp hosts: localhost diff --git a/linux/guest_customization/gosc_perl_staticip.yml b/linux/guest_customization/gosc_perl_staticip.yml index d3dc912f8..f9015c496 100644 --- a/linux/guest_customization/gosc_perl_staticip.yml +++ b/linux/guest_customization/gosc_perl_staticip.yml @@ -4,7 +4,7 @@ # Description: # This test case is used for check traditional perl guest customization # with VM static network configuration. If VMware tools is not installed -# or not running, this test case result is "No Run". +# or not running, this test case result is "Blocked". # - name: gosc_perl_staticip hosts: localhost diff --git a/linux/memory_hot_add_basic/memory_hot_add_basic.yml b/linux/memory_hot_add_basic/memory_hot_add_basic.yml index 2b3c49028..e39a1d4fc 100644 --- a/linux/memory_hot_add_basic/memory_hot_add_basic.yml +++ b/linux/memory_hot_add_basic/memory_hot_add_basic.yml @@ -5,7 +5,7 @@ # This test case is used for check VM memory hotadd works as expected. When calculated # memory hotadd size list from free memory size on ESXi server and the configured # maximum memory size (default 16384MB) is empty, or the free memory size on ESXi server -# is lower than 4096MB, this test case result is 'No Run'. +# is lower than 4096MB, this test case result is 'Blocked'. # Note: Linux VM memory size will be set to 2048MB before hotadd test. # - name: memory_hot_add_basic diff --git a/linux/stat_balloon/stat_balloon.yml b/linux/stat_balloon/stat_balloon.yml index 4155ac824..294bb921c 100644 --- a/linux/stat_balloon/stat_balloon.yml +++ b/linux/stat_balloon/stat_balloon.yml @@ -5,7 +5,7 @@ # This test case is used for check 'vmware-toolbox-cmd' command can display # the amount of memory that is currently reclaimed from the VM through ballooning. # Here the checked value is 0 MB, but it can be the real value according to specific situation. -# If VMware Tools is not installed or not running, then this test case result will be "No Run". +# If VMware Tools is not installed or not running, then this test case result will be "Blocked". # - name: stat_balloon hosts: localhost diff --git a/linux/stat_hosttime/stat_hosttime.yml b/linux/stat_hosttime/stat_hosttime.yml index 3f313857f..da25ffafb 100644 --- a/linux/stat_hosttime/stat_hosttime.yml +++ b/linux/stat_hosttime/stat_hosttime.yml @@ -4,7 +4,7 @@ # Description: # This test case is used for check 'vmware-toolbox-cmd' command can display # the date and time on the host. If VMware Tools is not installed or not running, -# then this test case result will be "No Run". +# then this test case result will be "Blocked". # Note: The difference between host time got from 'vmware-toolbox-cmd' in VM and # the host time got from ESXi host may not in 15s due to network issue. # diff --git a/linux/utils/enable_vmtools_logging.yml b/linux/utils/enable_vmtools_logging.yml new file mode 100644 index 000000000..f7860d1dc --- /dev/null +++ b/linux/utils/enable_vmtools_logging.yml @@ -0,0 +1,83 @@ +# Copyright 2023 VMware, Inc. +# SPDX-License-Identifier: BSD-2-Clause +--- +# Enable debug logging for VMware Tools within Linux guest OS +# See https://kb.vmware.com/s/article/1007873 for details. +# Parameters: +# vmtools_log_dir: The log directory in guest OS for VMware Tools debug logs +# +- name: "Set default VMware Tools debug log directory" + ansible.builtin.set_fact: + vmtools_log_dir: "/tmp/vmware-tools" + when: vmtools_log_dir is undefined or not vmtools_log_dir + +- name: "Set facts of VMware Tools config file and log files" + ansible.builtin.set_fact: + vmtools_config_file: "/etc/vmware-tools/tools.conf" + vmtools_vmtoolsd_log_file: "{{ vmtools_log_dir }}/vmtoolsd.log" + vmtools_vmsvc_log_file: "{{ vmtools_log_dir }}/vmsvc.log" + +- name: "Set facts of VMware Tools config section and options for enabling debug logging" + ansible.builtin.set_fact: + vmtools_logging_section: logging + vmtools_logging_options: |- + log=true + vmtoolsd.level=debug + vmtoolsd.handler=file + vmtoolsd.data={{ vmtools_vmtoolsd_log_file }} + vmsvc.level=debug + vmsvc.handler=file + vmsvc.data={{ vmtools_vmsvc_log_file }} + +- name: "Prepare log directory {{ vmtools_log_dir }} for new logs" + ansible.builtin.shell: | + if [ -e {{ vmtools_log_dir }} ] ; then + rm -rf {{ vmtools_log_dir }}; + fi + mkdir -p {{ vmtools_log_dir }} + delegate_to: "{{ vm_guest_ip }}" + +- name: "Get VMware Tools config file stat info" + include_tasks: get_file_stat_info.yml + vars: + guest_file_path: "{{ vmtools_config_file }}" + +- name: "Create VMware Tools config file with logging options" + ansible.builtin.copy: + dest: "{{ vmtools_config_file }}" + content: | + [{{ vmtools_logging_section }}] + {{ vmtools_logging_options }} + delegate_to: "{{ vm_guest_ip }}" + when: not guest_file_exists + +- name: "Update VMware Tools config file with logging options" + include_tasks: ../../common/update_ini_style_file.yml + vars: + file_path: "{{ vmtools_config_file }}" + section_name: "{{ vmtools_logging_section }}" + option_name: "{{ item.key }}" + option_value: "{{ item.value }}" + ini_state: present + loop: "{{ vmtools_logging_options | replace('=',': ') | from_yaml | dict2items }}" + when: guest_file_exists + +- name: "Get content of {{ vmtools_config_file }}" + ansible.builtin.shell: "cat {{ vmtools_config_file }}" + changed_when: false + delegate_to: "{{ vm_guest_ip }}" + register: vmtools_config + +- name: "Display content of {{ vmtools_config_file }}" + ansible.builtin.debug: var=vmtools_config + when: enable_debug + +- name: "Get the service name of VMware Tools" + include_tasks: set_ovt_facts.yml + +- name: "Restart vmtoolsd service to make config take effect" + include_tasks: service_operation.yml + vars: + service_name: "{{ ovt_service }}" + service_enabled: true + service_state: "restarted" diff --git a/linux/vgauth_check_service/vgauth_check_service.yml b/linux/vgauth_check_service/vgauth_check_service.yml index 79695086f..278e9bc89 100644 --- a/linux/vgauth_check_service/vgauth_check_service.yml +++ b/linux/vgauth_check_service/vgauth_check_service.yml @@ -4,7 +4,7 @@ # Description: # This test case is used for check 'VGAuth' service status in guest OS. # If VMware Tools is not installed or not running, then this test case -# result will be "No Run". +# result will be "Blocked". # - name: vgauth_check_service hosts: localhost