From e03f031034397e611ad03ddc49ff9cf152c3f331 Mon Sep 17 00:00:00 2001 From: "Qi (Keira) Zhang" Date: Mon, 14 Aug 2023 21:08:04 +0800 Subject: [PATCH] [Linux] Shutdown guest OS after auto install completes instead of rebooting (#489) Signed-off-by: Qi Zhang --- autoinstall/BCLinux-for-Euler/21.10/ks.cfg | 4 +- autoinstall/BCLinux/8/ks.cfg | 4 +- autoinstall/CentOS/7/ks.cfg | 4 +- autoinstall/CentOS/7/minimal/ks.cfg | 4 +- autoinstall/Debian/10/preseed.cfg | 3 + autoinstall/Fedora/36/Server/ks.cfg | 4 +- autoinstall/FreeBSD/installerconfig | 4 +- autoinstall/Pardus/preseed.cfg | 3 + autoinstall/RHEL/7/server_with_GUI/ks.cfg | 4 +- autoinstall/RHEL/7/server_without_GUI/ks.cfg | 4 +- autoinstall/RHEL/8/server_with_GUI/ks.cfg | 4 +- autoinstall/RHEL/8/server_without_GUI/ks.cfg | 4 +- autoinstall/SLE/15/SP3/SLED/autoinst.xml | 1 + autoinstall/SLE/15/SP3/SLES/autoinst.xml | 1 + .../SLE/15/SP3/SLES_Minimal/autoinst.xml | 1 + autoinstall/SLE/15/SP4/SLED/autoinst.xml | 1 + autoinstall/UOS/Server/20/1050a/ks.cfg | 4 +- autoinstall/UOS/Server/20/1050e/ks.cfg | 4 +- .../Ubuntu/Desktop/Subiquity/user-data.j2 | 2 +- .../Ubuntu/Desktop/Ubiquity/ubuntu.seed | 6 +- autoinstall/Ubuntu/Server/user-data.j2 | 2 + autoinstall/openSUSE/15/autoinst.xml | 3 +- ...so.yml => delete_unattend_install_iso.yml} | 15 +- linux/deploy_vm/deploy_vm_from_iso.yml | 244 +++++++++--------- .../rebuild_photon_unattend_install_iso.yml | 2 +- .../rebuild_ubuntu_unattend_install_iso.yml | 8 +- linux/utils/shutdown.yml | 11 +- 27 files changed, 181 insertions(+), 170 deletions(-) rename linux/deploy_vm/{eject_del_unattend_install_iso.yml => delete_unattend_install_iso.yml} (79%) diff --git a/autoinstall/BCLinux-for-Euler/21.10/ks.cfg b/autoinstall/BCLinux-for-Euler/21.10/ks.cfg index 9476876e9..4b9fc32dd 100644 --- a/autoinstall/BCLinux-for-Euler/21.10/ks.cfg +++ b/autoinstall/BCLinux-for-Euler/21.10/ks.cfg @@ -42,8 +42,8 @@ services --disabled="firewalld" # System timezone timezone America/New_York --isUtc -# Reboot when the install is finished. -reboot +# Shutdown when the install is finished. +shutdown %packages @^graphical-server-environment diff --git a/autoinstall/BCLinux/8/ks.cfg b/autoinstall/BCLinux/8/ks.cfg index 31c3593c0..86e0bca76 100644 --- a/autoinstall/BCLinux/8/ks.cfg +++ b/autoinstall/BCLinux/8/ks.cfg @@ -41,8 +41,8 @@ services --disabled="firewalld" # System timezone timezone America/New_York --isUtc -# Reboot when the install is finished. -reboot +# Shutdown when the install is finished. +shutdown %packages @^graphical-server-environment diff --git a/autoinstall/CentOS/7/ks.cfg b/autoinstall/CentOS/7/ks.cfg index 7a2f6f431..422293370 100644 --- a/autoinstall/CentOS/7/ks.cfg +++ b/autoinstall/CentOS/7/ks.cfg @@ -46,8 +46,8 @@ clearpart --none --initlabel services --disabled=firewalld eula --agreed -# Reboot when installation finished -reboot +# Shutdown when installation finished +shutdown %packages @^graphical-server-environment diff --git a/autoinstall/CentOS/7/minimal/ks.cfg b/autoinstall/CentOS/7/minimal/ks.cfg index aae680aff..ffb9a5500 100644 --- a/autoinstall/CentOS/7/minimal/ks.cfg +++ b/autoinstall/CentOS/7/minimal/ks.cfg @@ -43,8 +43,8 @@ clearpart --none --initlabel services --disabled=firewalld eula --agreed -# Reboot when installation finished -reboot +# Shutdown when installation finished +shutdown %packages @^minimal diff --git a/autoinstall/Debian/10/preseed.cfg b/autoinstall/Debian/10/preseed.cfg index f1b983369..40eb33064 100644 --- a/autoinstall/Debian/10/preseed.cfg +++ b/autoinstall/Debian/10/preseed.cfg @@ -195,6 +195,9 @@ d-i grub-installer/bootdev string default # Avoid that last message about the install being complete. d-i finish-install/reboot_in_progress note +# Shutdown after installation completes +d-i debian-installer/exit/poweroff boolean true + # This will prevent the installer from ejecting the CD during the reboot, # which is useful in some situations. #d-i cdrom-detect/eject boolean false diff --git a/autoinstall/Fedora/36/Server/ks.cfg b/autoinstall/Fedora/36/Server/ks.cfg index 1d48eb06e..429e9d5f8 100644 --- a/autoinstall/Fedora/36/Server/ks.cfg +++ b/autoinstall/Fedora/36/Server/ks.cfg @@ -53,8 +53,8 @@ user --name={{ new_user }} --password={{ vm_password_hash }} --groups=root,wheel sshkey --username={{ new_user }} "{{ ssh_public_key }}" {% endif %} -# Reboot when the install is finished. -reboot +# Shutdown when the install is finished. +shutdown %post --interpreter=/usr/bin/bash --log=/root/ks-post.log if [ -f /etc/cloud/cloud.cfg ]; then diff --git a/autoinstall/FreeBSD/installerconfig b/autoinstall/FreeBSD/installerconfig index 46a215369..caf4d139a 100644 --- a/autoinstall/FreeBSD/installerconfig +++ b/autoinstall/FreeBSD/installerconfig @@ -142,4 +142,6 @@ echo 'autoboot_delay="3"' >> /boot/loader.conf echo "End of installerconfig" > /dev/ttyu0 echo "{{ autoinstall_complete_msg }}" > /dev/ttyu0 -shutdown -r now + +# Power off system when autoinstall completes +poweroff diff --git a/autoinstall/Pardus/preseed.cfg b/autoinstall/Pardus/preseed.cfg index d2e78b4d7..e99f1dc28 100644 --- a/autoinstall/Pardus/preseed.cfg +++ b/autoinstall/Pardus/preseed.cfg @@ -189,6 +189,9 @@ d-i grub-installer/bootdev string default # Avoid that last message about the install being complete. d-i finish-install/reboot_in_progress note +# Shutdown after installation completes +d-i debian-installer/exit/poweroff boolean true + # This will prevent the installer from ejecting the CD during the reboot, # which is useful in some situations. #d-i cdrom-detect/eject boolean true diff --git a/autoinstall/RHEL/7/server_with_GUI/ks.cfg b/autoinstall/RHEL/7/server_with_GUI/ks.cfg index 81ec5a31f..56ec15ce1 100644 --- a/autoinstall/RHEL/7/server_with_GUI/ks.cfg +++ b/autoinstall/RHEL/7/server_with_GUI/ks.cfg @@ -46,8 +46,8 @@ clearpart --none --initlabel services --disabled=firewalld eula --agreed -# Reboot when the install is finished. -reboot +# Shutdown when the install is finished. +shutdown %packages diff --git a/autoinstall/RHEL/7/server_without_GUI/ks.cfg b/autoinstall/RHEL/7/server_without_GUI/ks.cfg index da27fdf35..5a2e6fa2d 100644 --- a/autoinstall/RHEL/7/server_without_GUI/ks.cfg +++ b/autoinstall/RHEL/7/server_without_GUI/ks.cfg @@ -46,8 +46,8 @@ clearpart --none --initlabel services --disabled=firewalld eula --agreed -# Reboot when the install is finished. -reboot +# Shutdown when the install is finished. +shutdown %packages @^infrastructure-server-environment diff --git a/autoinstall/RHEL/8/server_with_GUI/ks.cfg b/autoinstall/RHEL/8/server_with_GUI/ks.cfg index ba894411f..50f128fb8 100644 --- a/autoinstall/RHEL/8/server_with_GUI/ks.cfg +++ b/autoinstall/RHEL/8/server_with_GUI/ks.cfg @@ -41,8 +41,8 @@ services --disabled="firewalld" # System timezone timezone America/New_York --isUtc -# Reboot when the install is finished. -reboot +# Shutdown when the install is finished. +shutdown %packages @^graphical-server-environment diff --git a/autoinstall/RHEL/8/server_without_GUI/ks.cfg b/autoinstall/RHEL/8/server_without_GUI/ks.cfg index 9c0e179d5..2c8766a96 100644 --- a/autoinstall/RHEL/8/server_without_GUI/ks.cfg +++ b/autoinstall/RHEL/8/server_without_GUI/ks.cfg @@ -39,8 +39,8 @@ services --enabled="chronyd" # System timezone timezone America/New_York --isUtc -# Reboot when the install is finished. -reboot +# Shutdown when the install is finished. +shutdown %packages @^server-product-environment kexec-tools diff --git a/autoinstall/SLE/15/SP3/SLED/autoinst.xml b/autoinstall/SLE/15/SP3/SLED/autoinst.xml index 821686363..b969dd9e3 100644 --- a/autoinstall/SLE/15/SP3/SLED/autoinst.xml +++ b/autoinstall/SLE/15/SP3/SLED/autoinst.xml @@ -220,6 +220,7 @@ false + true diff --git a/autoinstall/SLE/15/SP3/SLES/autoinst.xml b/autoinstall/SLE/15/SP3/SLES/autoinst.xml index ca04568b4..698ffdbee 100644 --- a/autoinstall/SLE/15/SP3/SLES/autoinst.xml +++ b/autoinstall/SLE/15/SP3/SLES/autoinst.xml @@ -184,6 +184,7 @@ false + true diff --git a/autoinstall/SLE/15/SP3/SLES_Minimal/autoinst.xml b/autoinstall/SLE/15/SP3/SLES_Minimal/autoinst.xml index ce107084f..2f4ceec88 100644 --- a/autoinstall/SLE/15/SP3/SLES_Minimal/autoinst.xml +++ b/autoinstall/SLE/15/SP3/SLES_Minimal/autoinst.xml @@ -48,6 +48,7 @@ false + true diff --git a/autoinstall/SLE/15/SP4/SLED/autoinst.xml b/autoinstall/SLE/15/SP4/SLED/autoinst.xml index 36e6e5c14..7f0b72e74 100644 --- a/autoinstall/SLE/15/SP4/SLED/autoinst.xml +++ b/autoinstall/SLE/15/SP4/SLED/autoinst.xml @@ -215,6 +215,7 @@ false + true diff --git a/autoinstall/UOS/Server/20/1050a/ks.cfg b/autoinstall/UOS/Server/20/1050a/ks.cfg index cbf6bf942..31eb1f71a 100644 --- a/autoinstall/UOS/Server/20/1050a/ks.cfg +++ b/autoinstall/UOS/Server/20/1050a/ks.cfg @@ -43,8 +43,8 @@ services --enabled="chronyd" # System timezone timezone America/New_York --utc -# Reboot when the install is finished. -reboot +# Shutdown when the install is finished. +shutdown %packages @Server with DDE diff --git a/autoinstall/UOS/Server/20/1050e/ks.cfg b/autoinstall/UOS/Server/20/1050e/ks.cfg index 6d5287119..f1623e035 100644 --- a/autoinstall/UOS/Server/20/1050e/ks.cfg +++ b/autoinstall/UOS/Server/20/1050e/ks.cfg @@ -49,8 +49,8 @@ services --enabled="chronyd" # System timezone timezone America/New_York --isUtc -# Reboot when the install is finished. -reboot +# Shutdown when the install is finished. +shutdown %anaconda pwpolicy root --minlen=6 --minquality=1 --notstrict --nochanges --notempty diff --git a/autoinstall/Ubuntu/Desktop/Subiquity/user-data.j2 b/autoinstall/Ubuntu/Desktop/Subiquity/user-data.j2 index 826b4d1b9..411f5656b 100644 --- a/autoinstall/Ubuntu/Desktop/Subiquity/user-data.j2 +++ b/autoinstall/Ubuntu/Desktop/Subiquity/user-data.j2 @@ -44,4 +44,4 @@ autoinstall: - sed -i 's/^#PermitRootLogin .*/PermitRootLogin yes/' /target/etc/ssh/sshd_config - sed -i 's/^#PasswordAuthentication .*/PasswordAuthentication yes/' /target/etc/ssh/sshd_config - echo "{{ autoinstall_complete_msg }}" >> /dev/ttyS0 - shutdown: 'reboot' + shutdown: 'poweroff' diff --git a/autoinstall/Ubuntu/Desktop/Ubiquity/ubuntu.seed b/autoinstall/Ubuntu/Desktop/Ubiquity/ubuntu.seed index 92bfa22df..4e74283b1 100644 --- a/autoinstall/Ubuntu/Desktop/Ubiquity/ubuntu.seed +++ b/autoinstall/Ubuntu/Desktop/Ubiquity/ubuntu.seed @@ -43,7 +43,7 @@ d-i passwd/root-password-crypted password {{ vm_password_md5 }} d-i user-setup/allow-password-weak boolean true d-i pkgsel/language-packs multiselect en, zh -d-i pkgsel/update-policy select none +d-i pkgsel/update-policy select none d-i pkgsel/upgrade select none # By default, the system's locate database will be updated after the @@ -75,10 +75,10 @@ ubiquity ubiquity/success_command \ in-target chmod 0644 /root/.ssh/authorized_keys; \ in-target sed -i 's/#PasswordAuthentication.*/PasswordAuthentication yes/' /etc/ssh/sshd_config; \ in-target sed -i 's/#PermitRootLogin.*/PermitRootLogin yes/' /etc/ssh/sshd_config; \ - echo "{{ autoinstall_complete_msg }}" > /target/dev/ttyS0 + echo "{{ autoinstall_complete_msg }}" >/dev/ttyS0 d-i finish-install/reboot_in_progress note d-i cdrom-detect/eject boolean true ubiquity ubiquity/summary note -ubiquity ubiquity/reboot boolean true +ubiquity ubiquity/poweroff boolean true diff --git a/autoinstall/Ubuntu/Server/user-data.j2 b/autoinstall/Ubuntu/Server/user-data.j2 index c44255792..dbec0c6f1 100644 --- a/autoinstall/Ubuntu/Server/user-data.j2 +++ b/autoinstall/Ubuntu/Server/user-data.j2 @@ -55,3 +55,5 @@ autoinstall: - echo 'Acquire::ForceIPv4 "true";' >>/etc/apt/apt.conf.d/99force-ipv4 - sed -i 's/^#PermitRootLogin .*/PermitRootLogin yes/' /target/etc/ssh/sshd_config - sed -i 's/^#PasswordAuthentication .*/PasswordAuthentication yes/' /target/etc/ssh/sshd_config + - echo "{{ autoinstall_complete_msg }}" >/dev/ttyS0 + shutdown: 'poweroff' diff --git a/autoinstall/openSUSE/15/autoinst.xml b/autoinstall/openSUSE/15/autoinst.xml index 0c41e171f..efac55071 100644 --- a/autoinstall/openSUSE/15/autoinst.xml +++ b/autoinstall/openSUSE/15/autoinst.xml @@ -212,6 +212,7 @@ false + true @@ -1416,4 +1417,4 @@ - \ No newline at end of file + diff --git a/linux/deploy_vm/eject_del_unattend_install_iso.yml b/linux/deploy_vm/delete_unattend_install_iso.yml similarity index 79% rename from linux/deploy_vm/eject_del_unattend_install_iso.yml rename to linux/deploy_vm/delete_unattend_install_iso.yml index 6612d3fea..b5c4717e6 100644 --- a/linux/deploy_vm/eject_del_unattend_install_iso.yml +++ b/linux/deploy_vm/delete_unattend_install_iso.yml @@ -1,17 +1,8 @@ -# Copyright 2021-2023 VMware, Inc. +# Copyright 2023 VMware, Inc. # SPDX-License-Identifier: BSD-2-Clause --- -# Eject CDROM of unattend install ISO in guest OS -- include_tasks: ../utils/eject_cdrom_in_guest.yml - vars: - guest_cdrom_device_num: "{{ os_install_iso_list_len | int -1 }}" - when: guest_os_family != "FreeBSD" - -- name: "Eject CD for FreeBSD" - ansible.builtin.command: "camcontrol eject /dev/cd0" - delegate_to: "{{ vm_guest_ip }}" - when: guest_os_family == "FreeBSD" - +# Delete unattend install ISO file +# # By default, it's attached to the last CDROM in composed VM CDROMs list - name: "Set fact of the controller and unit number of CDROM attaching unattend install ISO" ansible.builtin.set_fact: diff --git a/linux/deploy_vm/deploy_vm_from_iso.yml b/linux/deploy_vm/deploy_vm_from_iso.yml index ea9b9ffd5..2c176ca0f 100644 --- a/linux/deploy_vm/deploy_vm_from_iso.yml +++ b/linux/deploy_vm/deploy_vm_from_iso.yml @@ -18,6 +18,18 @@ - cpu_number is undefined or not cpu_number - cpu_cores_per_socket is defined and cpu_cores_per_socket +# Installing FreeBSD 32bit on lsilogic/lsilogicsas/nvme disk will +# fail when memory size >= 4 GB +- name: "Set the fact of memory size for the new VM" + ansible.builtin.set_fact: + vm_memory_mb: |- + {%- if guest_id is match('freebsd\\d+Guest') and + boot_disk_controller in ['lsilogic', 'lsilogicsas', 'nvme'] -%} + {{ [3072, memory_mb | default(4096) | int ] | min }} + {%- else -%} + {{ memory_mb | default(4096) | int }} + {%- endif -%} + - name: "Update test case name for deploying VM from ISO image" ansible.builtin.set_fact: current_testcase_name: "deploy_vm_{{ firmware }}_{{ boot_disk_controller }}_{{ network_adapter_type }}" @@ -33,9 +45,10 @@ - name: "Prepare for Ubuntu installation" include_tasks: ubuntu/prepare_ubuntu_iso_install.yml - when: "'ubuntu' in guest_id" + when: guest_id is match('ubuntu.*') - name: "Set default unattend install conf file" + when: unattend_install_conf is undefined or not unattend_install_conf block: - name: "Set default unattend install conf file for VMware Photon OS" ansible.builtin.set_fact: @@ -50,8 +63,7 @@ - name: "Set default unattend install conf file for FreeBSD" ansible.builtin.set_fact: unattend_install_conf: "FreeBSD/installerconfig" - when: "'freebsd' in guest_id" - when: unattend_install_conf is undefined or not unattend_install_conf + when: guest_id is match('freebsd.*') - name: "Display warning message about undefined unattend_install_conf" ansible.builtin.debug: @@ -65,20 +77,6 @@ - name: "Compose VM CDROMs to mount OS install ISO files" include_tasks: ../../common/compose_vm_cdroms.yml - # Failed to install FreeBSD 32bit with lsilogic/lsilogicsas/nvme when memory >= 4G - - name: "Initialize the fact of memory size when create VM" - ansible.builtin.set_fact: - vm_memory_mb: |- - {%- if guest_id is match('freebsd\\d+Guest') and boot_disk_controller in ['lsilogic', 'lsilogicsas', 'nvme'] -%} - {{ [3072, memory_mb | default(4096) | int ] | min }} - {%- else -%} - {{ memory_mb | default(4096) | int }} - {%- endif -%} - - - name: "Display the memory size when create VM" - ansible.builtin.debug: var=vm_memory_mb - when: enable_debug is defined and enable_debug - - name: "Create a new VM with {{ boot_disk_controller }} disk" include_tasks: ../../common/vm_create.yml vars: @@ -87,6 +85,8 @@ - name: "Create a new VM with {{ boot_disk_controller }} disk" include_tasks: ../../common/vm_create_with_ide_disk.yml + vars: + memory_mb: "{{ vm_memory_mb }}" when: boot_disk_controller == 'ide' - name: "Get VM info" @@ -100,6 +100,7 @@ include_tasks: ../../common/vm_add_serial_port.yml - name: "Set video memory size" + when: install_guest_with_desktop block: - name: "Get VM's video card info" include_tasks: ../../common/vm_get_video_card.yml @@ -113,7 +114,6 @@ vars: video_memory_mb: 8 when: vm_default_video_memory_mb | int < 8 - when: install_guest_with_desktop - name: "Enable secure boot on VM" include_tasks: ../../common/vm_set_boot_options.yml @@ -154,7 +154,7 @@ - name: "Install Ubuntu OS" include_tasks: ubuntu/ubuntu_install_os.yml - when: "'ubuntu' in guest_id" + when: guest_id is match('ubuntu.*') # For SLES, OS installation with BIOS firmware, send key to boot # screen to start new installation instead of booting from local @@ -195,16 +195,6 @@ - unattend_install_conf is defined - ('UOS' in unattend_install_conf) - # We can get the text "ubuntu login:" from the serial output when the installer begin to run - # but get this text again after finish installation and reboot - # When we get text "gdm.service", We are so close to the state "system is up" after rebooting. - - name: "Set autoinstall complete message for Ubuntu Desktop 20.04 ~ 22.10" - ansible.builtin.set_fact: - autoinstall_complete_msg: "gdm.service" - when: - - unattend_install_conf is defined - - unattend_install_conf is match('Ubuntu/Desktop/Ubiquity') - - name: "Wait autoinstall complete message appear in serial port output file" include_tasks: ../../common/vm_wait_log_msg.yml vars: @@ -213,12 +203,80 @@ vm_wait_log_delay: 30 vm_wait_log_retries: 120 - - name: "Wait 60s for OS rebooting" - ansible.builtin.pause: - seconds: 60 + - name: "Take a screenshot when autoinstall complete message is received" + include_tasks: ../../common/vm_take_screenshot.yml + vars: + vm_take_screenshot_local_path: "{{ current_test_log_folder }}" + + # VMware Photon OS kickstart file can't add shutdown action, + # so here needs to shutdown it separately + - name: "Shutdown VMware Photon OS VM after auto install completes" + when: + - unattend_install_conf is defined + - unattend_install_conf is match('Photon') + block: + - name: "Wait for guest full name on VMware Photon OS VM" + include_tasks: ../../common/vm_wait_guest_fullname.yml + + - name: "Get guest IP address" + include_tasks: ../../common/update_inventory.yml + vars: + update_inventory_timeout: 300 + + - name: "Shutdown guest OS to remove serial port" + include_tasks: ../utils/shutdown.yml + + - name: "Wait for VM being powered off" + include_tasks: ../../common/vm_wait_power_state.yml + vars: + expected_power_status: 'poweredOff' + wait_power_state_timeout: 600 + + - name: "Delete unattend install ISO" + include_tasks: delete_unattend_install_iso.yml + when: + - transferred_unattend_iso is defined + - transferred_unattend_iso + + - name: "Change the boot disk to be first boot device in boot order" + include_tasks: ../../common/vm_set_boot_options.yml + vars: + boot_order_list: ['disk'] + when: guest_id is match('ubuntu.*') + + - name: "Download serial output file before removing serial port" + include_tasks: ../../common/esxi_download_datastore_file.yml + vars: + src_datastore: "{{ datastore }}" + src_file_path: "{{ vm_dir_name }}/{{ vm_serial_port_output_file | basename }}" + dest_file_path: "{{ current_test_log_folder }}/{{ vm_serial_port_output_file | basename }}" + download_file_fail_ignore: true + when: + - vm_dir_name is defined + - vm_dir_name + - vm_serial_port_output_file is defined + - vm_serial_port_output_file + + - name: "Remove serial port" + include_tasks: ../../common/vm_remove_serial_port.yml + + - name: "Failed to remove serial port" + ansible.builtin.fail: + msg: "Failed to remove serial port from VM" + when: > + remove_serial_port is undefined or + remove_serial_port.changed is undefined or + not remove_serial_port.changed + + - name: "OS auto install is completed. Power on VM now" + include_tasks: ../../common/vm_set_power_state.yml + vars: + vm_power_state_set: 'powered-on' - name: "Wait for guest full name is collected" include_tasks: ../../common/vm_wait_guest_fullname.yml + vars: + vm_get_fullname_timeout: 600 when: - unattend_install_conf is defined - unattend_install_conf | lower is not match('.*(minimal|server_without_gui|bclinux-for-euler).*') @@ -232,6 +290,10 @@ include_tasks: ../utils/get_linux_system_info.yml - name: "Wait for guest OS service is ready" + when: + - guest_os_with_gui is defined + - (guest_os_family in ["RedHat", "Suse"] or + guest_os_ansible_distribution in ["Ubuntu", "Debian"]) block: # For SLE, RHEL8/CentOS8/OracleLinux8 with desktop: display-manager # service running at the end of installation to wait user login. @@ -249,18 +311,12 @@ vars: service_name: "{{ wait_service_name }}" wait_service_status: "running" - when: - - guest_os_with_gui is defined - - (guest_os_family in ["RedHat", "Suse"] or - guest_os_ansible_distribution in ["Ubuntu", "Debian"]) - - - name: "Eject unattend/seed ISO and delete it from datastore" - include_tasks: eject_del_unattend_install_iso.yml - when: - - transferred_unattend_iso is defined - - transferred_unattend_iso - name: "Upgrade Oracle Linux 9.0 kernel from UEK R7 GA to latest UEK R7" + when: + - guest_os_ansible_distribution == "OracleLinux" + - guest_os_ansible_distribution_ver == "9.0" + - "'uek' in guest_os_ansible_kernel" block: - include_tasks: ../../common/vm_take_snapshot.yml vars: @@ -271,7 +327,9 @@ ol9_uekr7_is_upgraded: false ol9_uekr7_before_upgrade: "{{ guest_os_ansible_kernel }}" - - include_tasks: ../utils/add_official_online_repo.yml + - name: "Add Oracle Linux online repos for upgrading kernel" + include_tasks: ../utils/add_official_online_repo.yml + - name: "Update Oracle Linux 9.0 to latest UEK R7" ansible.builtin.shell: "yum update --nogpgcheck -y" register: ol9_uekr7_upgrade_result @@ -284,83 +342,31 @@ - ol9_uekr7_upgrade_result is defined - ol9_uekr7_upgrade_result.rc is defined - ol9_uekr7_upgrade_result.rc == 0 - when: - - guest_os_ansible_distribution == "OracleLinux" - - guest_os_ansible_distribution_ver == "9.0" - - "'uek' in guest_os_ansible_kernel" - - - name: "Shutdown guest OS" - include_tasks: ../utils/shutdown.yml - - - name: "Change CD/DVD to client device and set disk as first boot device for Ubuntu" - block: - - name: "Change VM's CD/DVD Drive 1 to client device" - include_tasks: ../../common/vm_configure_cdrom.yml - vars: - cdrom_state: present - cdrom_type: client - cdrom_controller_num: "{{ vm_cdroms[0].controller_number | int }}" - cdrom_unit_num: "{{ vm_cdroms[0].unit_number | int }}" - - - name: "Change the boot disk to be first in boot order" - include_tasks: ../../common/vm_set_boot_options.yml - vars: - boot_order_list: - - disk - when: guest_os_ansible_distribution == "Ubuntu" - - - name: "Download serial output file before removing serial port" - include_tasks: ../../common/esxi_download_datastore_file.yml - vars: - src_datastore: "{{ datastore }}" - src_file_path: "{{ vm_dir_name }}/{{ vm_serial_port_output_file | basename }}" - dest_file_path: "{{ current_test_log_folder }}/{{ vm_serial_port_output_file | basename }}" - download_file_fail_ignore: true - when: - - vm_dir_name is defined - - vm_dir_name - - vm_serial_port_output_file is defined - - vm_serial_port_output_file - - - name: "Remove serial port" - include_tasks: ../../common/vm_remove_serial_port.yml - - name: "Failed to remove serial port" - ansible.builtin.fail: - msg: "Failed to remove serial port from VM" - when: > - remove_serial_port is undefined or - remove_serial_port.changed is undefined or - not remove_serial_port.changed - - - name: "Power on VM" - include_tasks: ../../common/vm_set_power_state.yml - vars: - vm_power_state_set: 'powered-on' - - - name: "Check Oracle Linux 9.0 kernel UEK R7 is upgraded" - block: - - name: "Update VM guest IPv4 address in in-memory inventory" - include_tasks: ../../common/update_inventory.yml - - - name: "Refresh Linux system info" - include_tasks: ../utils/get_linux_system_info.yml - - - name: "Get Oracle Linux 9.0 UEK R7 version after upgrading" - ansible.builtin.set_fact: - ol9_uekr7_after_upgrade: "{{ guest_os_ansible_kernel }}" - - - name: "Check Oracle Linux 9.0 kernel UEK R7 is upgraded successfully" - ansible.builtin.assert: - that: - - ol9_uekr7_after_upgrade is version(ol9_uekr7_before_upgrade, '>') - fail_msg: >- - Oracle Linux 9.0 UEK R7 upgrading failed. Before upgrade, the UEK R7 - version is '{{ ol9_uekr7_before_upgrade }}', after upgrade the UEK R7 - version is '{{ ol9_uekr7_after_upgrade }}'. - when: - - ol9_uekr7_is_upgraded is defined - - ol9_uekr7_is_upgraded + - name: "Check Oracle Linux 9.0 kernel UEK R7 is upgraded" + when: ol9_uekr7_is_upgraded + block: + - name: "Reboot Oracle Linux" + include_tasks: ../utils/reboot.yml + + - name: "Update VM guest IPv4 address in in-memory inventory" + include_tasks: ../../common/update_inventory.yml + + - name: "Refresh Linux system info" + include_tasks: ../utils/get_linux_system_info.yml + + - name: "Get Oracle Linux 9.0 UEK R7 version after upgrading" + ansible.builtin.set_fact: + ol9_uekr7_after_upgrade: "{{ guest_os_ansible_kernel }}" + + - name: "Check Oracle Linux 9.0 kernel UEK R7 is upgraded successfully" + ansible.builtin.assert: + that: + - ol9_uekr7_after_upgrade is version(ol9_uekr7_before_upgrade, '>') + fail_msg: >- + Oracle Linux 9.0 UEK R7 upgrading failed. Before upgrade, the UEK R7 + version is '{{ ol9_uekr7_before_upgrade }}', after upgrade the UEK R7 + version is '{{ ol9_uekr7_after_upgrade }}'. rescue: - name: "Test case failure" diff --git a/linux/deploy_vm/rebuild_photon_unattend_install_iso.yml b/linux/deploy_vm/rebuild_photon_unattend_install_iso.yml index f51f5ac53..1bf381b64 100644 --- a/linux/deploy_vm/rebuild_photon_unattend_install_iso.yml +++ b/linux/deploy_vm/rebuild_photon_unattend_install_iso.yml @@ -26,7 +26,7 @@ ansible.builtin.replace: path: "{{ src_iso_file_dir }}/{{ item }}" regexp: '(.*)(root=[^ ]+)(.*)' - replace: "\\1\\2 ks=cdrom:/isolinux/{{ unattend_install_file_name }} \\3" + replace: "\\1\\2 ks=cdrom:/isolinux/{{ unattend_install_file_name }} console=ttyS0,115200n8 \\3" with_items: - "menu.cfg" - "grub.cfg" diff --git a/linux/deploy_vm/rebuild_ubuntu_unattend_install_iso.yml b/linux/deploy_vm/rebuild_ubuntu_unattend_install_iso.yml index b45fe9455..541c54474 100644 --- a/linux/deploy_vm/rebuild_ubuntu_unattend_install_iso.yml +++ b/linux/deploy_vm/rebuild_ubuntu_unattend_install_iso.yml @@ -103,7 +103,7 @@ ansible.builtin.replace: path: "{{ unattend_iso_cache }}/grub.cfg" regexp: '(.*vmlinuz)(.*)' - replace: "\\1 autoinstall \\2" + replace: "\\1 autoinstall console=ttyS0,115200n8 \\2" - name: "Set timeout to 5 seconds at boot menu" ansible.builtin.replace: @@ -144,7 +144,7 @@ ansible.builtin.replace: path: "{{ unattend_iso_cache }}/txt.cfg" regexp: '(.*initrd)(.*)' - replace: "\\1 autoinstall \\2" + replace: "\\1 autoinstall console=ttyS0,115200n8 \\2" - name: "Update md5sum for BIOS boot config file" ansible.builtin.shell: | @@ -176,4 +176,6 @@ - src_file: "{{ src_iso_file_dir }}/md5sum.txt" dest_file: "md5sum.txt" when: not ubuntu_bios_cfg_exist - when: unattend_install_conf is match('Ubuntu/Server') or unattend_install_conf is match('Ubuntu/Desktop/Subiquity') + when: >- + (unattend_install_conf is match('Ubuntu/Server') or + unattend_install_conf is match('Ubuntu/Desktop/Subiquity')) diff --git a/linux/utils/shutdown.yml b/linux/utils/shutdown.yml index 42a31c9dd..65b5e4024 100644 --- a/linux/utils/shutdown.yml +++ b/linux/utils/shutdown.yml @@ -1,13 +1,10 @@ # Copyright 2021-2023 VMware, Inc. # SPDX-License-Identifier: BSD-2-Clause --- -# Shutdown VM via executing shutdown command in VM -- name: "Set command to shutdown guestOS" - ansible.builtin.set_fact: - guest_shutdown_cmd: "{{ 'poweroff' if guest_os_family == 'FreeBSD' else 'shutdown -h now' }}" - -- name: Execute guest OS shutdown - ansible.builtin.command: "{{ guest_shutdown_cmd }}" +# Shutdown VM via executing 'poweroff' command in guest OS +# +- name: "Shutdown guest OS" + ansible.builtin.command: "poweroff" delegate_to: "{{ vm_guest_ip }}" become: true changed_when: false