diff --git a/README.md b/README.md index 582ae00e7..10753bf47 100644 --- a/README.md +++ b/README.md @@ -87,6 +87,8 @@ This project supports below scenarios for end-to-end guest operating system vali | UnionTech OS Server 20 1050a | :heavy_check_mark: | | :heavy_check_mark: | | Fedora Server 36 and later | :heavy_check_mark: | | :heavy_check_mark: | | ProLinux Server 7.9, 8.5 | :heavy_check_mark: | | :heavy_check_mark: | +| Pardus 21.2 Server and later | :heavy_check_mark: | | :heavy_check_mark: | +| Pardus 21.2 XFCE Desktop and later | :heavy_check_mark: | | :heavy_check_mark: | Note: This compatible guest operating systems list is used for this project only. For guest operating system support status on ESXi, please refer to [VMware Compatibility Guide](https://www.vmware.com/resources/compatibility/search.php?deviceCategory=software&testConfig=16). diff --git a/autoinstall/Pardus/preseed.cfg b/autoinstall/Pardus/preseed.cfg new file mode 100644 index 000000000..d2e78b4d7 --- /dev/null +++ b/autoinstall/Pardus/preseed.cfg @@ -0,0 +1,252 @@ +#_preseed_V1 +#### Contents of the preconfiguration file (for pardus) + +### Localization +# Preseeding only locale sets language, country and locale. +d-i debconf/language string en_US:en +d-i debian-installer/country string US +d-i debian-installer/fallbacklocale string en_US +d-i debian-installer/language string en_US:en +d-i languagechooser/locale string en +d-i debian-installer/locale string en_US + +# Keyboard selection. +d-i keyboard-configuration/xkb-keymap select us +d-i keyboard-configuration/variant select English (US) + +### Network configuration +d-i netcfg/enable boolean true + +# netcfg will choose an interface that has link if possible. This makes it +# skip displaying a list if there is more than one interface. +d-i netcfg/choose_interface select auto +d-i netcfg/use_dhcp string true + +# To set a different link detection timeout (default is 3 seconds). +# Values are interpreted as seconds. +d-i netcfg/link_wait_timeout string 10 + +# If you have a slow dhcp server and the installer times out waiting for +# it, this might be useful. +d-i netcfg/dhcp_timeout string 60 + +# If you want the preconfiguration file to work on systems both with and +# without a dhcp server, uncomment these lines and the static network +# configuration below. +d-i netcfg/dhcp_failed note + +# Any hostname and domain names assigned from dhcp take precedence over +# values set here. However, setting the values still prevents the questions +# from being shown, even if values come from dhcp. +d-i netcfg/get_hostname string pardus +d-i netcfg/get_domain string unassigned-domain + +### Clock and time zone setup +# Controls whether or not the hardware clock is set to UTC. +d-i clock-setup/utc boolean true + +# You may set this to any valid setting for $TZ; see the contents of +# /usr/share/zoneinfo/ for valid values. +d-i time/zone string US/Eastern + +# Controls whether to use NTP to set the clock during the install +d-i clock-setup/ntp boolean true +# NTP server to use. The default is almost always fine here. +#d-i clock-setup/ntp-server string ntp.example.com +d-i console-setup/ask_detect boolean false +d-i console-setup/layoutcode string us + +### Account setup +# Root password encrypted using a crypt(3) hash. +d-i passwd/root-login boolean true +d-i passwd/root-password-crypted password {{ vm_password_hash }} + +{% if new_user is defined and new_user != 'root' %} +# To create a normal user account. +d-i passwd/user-fullname string {{ new_user }} +d-i passwd/username string {{ new_user }} +# Normal user's password encrypted using a crypt(3) hash. +d-i passwd/user-password-crypted password {{ vm_password_hash }} + +# The user account will be added to some standard initial groups. To +# override that, use this. +d-i passwd/user-default-groups string root wheel +{% endif %} + +### Partitioning +## Partitioning example +# Specify a disk to partition. +# For example, to use the first SCSI/SATA hard disk: +d-i partman-auto/disk string /dev/{{ boot_disk_name }} +# In addition, you'll need to specify the method to use. +# The presently available methods are: +# - regular: use the usual partition types for your architecture +# - lvm: use LVM to partition the disk +# - crypto: use LVM within an encrypted partition +d-i partman-auto/method string lvm + +# You can define the amount of space that will be used for the LVM volume +# group. It can either be a size with its unit (eg. 20 GB), a percentage of +# free space or the 'max' keyword. +d-i partman-auto-lvm/guided_size string max + +# If one of the disks that are going to be automatically partitioned +# contains an old LVM configuration, the user will normally receive a +# warning. This can be preseeded away... +d-i partman-lvm/device_remove_lvm boolean true +# The same applies to pre-existing software RAID array: +d-i partman-md/device_remove_md boolean true +# And the same goes for the confirmation to write the lvm partitions. +d-i partman-lvm/confirm boolean true +d-i partman-lvm/confirm_nooverwrite boolean true + +# You can choose one of the three predefined partitioning recipes: +# - atomic: all files in one partition +# - home: separate /home partition +# - multi: separate /home, /var, and /tmp partitions +d-i partman-auto/choose_recipe select atomic + +# This makes partman automatically partition without confirmation, provided +# that you told it what to do using one of the methods above. +d-i partman-partitioning/confirm_write_new_label boolean true +d-i partman/choose_partition select finish +d-i partman/confirm boolean true +d-i partman/confirm_nooverwrite boolean true + +# Force UEFI booting ('BIOS compatibility' will be lost). Default: false. +{% if firmware is defined and firmware == 'efi' %} +d-i partman-efi/non_efi_system boolean true + +# Ensure the partition table is GPT - this is required for EFI +d-i partman-partitioning/choose_label string gpt +d-i partman-partitioning/default_label string gpt +{% endif %} + +# This makes partman automatically partition without confirmation. +d-i partman-md/confirm boolean true +d-i partman-partitioning/confirm_write_new_label boolean true +d-i partman/choose_partition select finish +d-i partman/confirm boolean true +d-i partman/confirm_nooverwrite boolean true + +# Default repository information (don't include codename data, d-i figures it +# out from what's available in the ISO) +#d-i mirror/country string manually +#d-i mirror/http/hostname string depo.pardus.org.tr +#d-i mirror/http/hostname seen false +#d-i mirror/http/directory string /pardus +#d-i mirror/http/proxy string +# Don't add any security and updates repo to avoid an upgrade during installation +# We might need these later, think about the following lines. +#d-i apt-setup/services-select multiselect +#d-i apt-setup/security_host string depo.pardus.org.tr +#d-i apt-setup/security_path string /guvenlik + +### Apt setup +d-i apt-setup/use_mirror boolean false +d-i apt-setup/cdrom/set-first boolean false +d-i apt-setup/cdrom/set-next boolean false +d-i apt-setup/cdrom/set-failed boolean false +d-i apt-setup/disable-cdrom-entries boolean true +d-i apt-setup/enable-source-repositories boolean true + +# Disable upgrading while installation +d-i pkgsel/upgrade select none + +### Package selection +#tasksel tasksel/first multiselect standard, web-server, kde-desktop +tasksel tasksel/first multiselect standard, desktop +tasksel tasksel/desktop multiselect xfce + +# Individual additional packages to install +# There is no open-vm-tools-desktop openssh-server and cloud-init in CDROM +#d-i pkgsel/include string build-essential open-vm-tools openssh-server sg3-utils vim + +# Policy for applying updates. May be "none" (no automatic updates), +# "unattended-upgrades" (install security updates automatically), or +# "landscape" (manage system with Landscape). +d-i pkgsel/update-policy select none + +# Some versions of the installer can report back on what software you have +# installed, and what software you use. The default is not to report back, +# but sending reports helps the project determine what software is most +# popular and should be included on the first CD/DVD. +popularity-contest popularity-contest/participate boolean false + +### Boot loader installation +# Grub is the boot loader (for x86). + +# This is fairly safe to set, it makes grub install automatically to the UEFI +# partition/boot record if no other operating system is detected on the machine. +d-i grub-installer/only_debian boolean true + +# Due notably to potential USB sticks, the location of the primary drive can +# not be determined safely in general, so this needs to be specified: +#d-i grub-installer/bootdev string /dev/sda +# To install to the primary device (assuming it is not a USB stick): +d-i grub-installer/bootdev string default + +# Avoid that last message about the install being complete. +d-i finish-install/reboot_in_progress note + +# 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 + +### Preseeding other packages +# Depending on what software you choose to install, or if things go wrong +# during the installation process, it's possible that other questions may +# be asked. You can preseed those too, of course. To get a list of every +# possible question that could be asked during an install, do an +# installation, and then run these commands: + debconf-get-selections --installer > /target/root/preceed.cfg + debconf-get-selections >> /target/root/preceed.cfg + +# This command is run just before the install finishes, but when there is +# still a usable /target directory. You can chroot to /target and use it +# directly, or use the apt-install and in-target commands to easily install +# packages and run commands in the target system. +# The packages not available in CDROM will be installed from online repo. +d-i preseed/late_command string \ + echo "Check network ..." > /target/dev/ttyS0; \ + ip addr show > /target/dev/ttyS0; \ + echo "Linkup network ..." > /target/dev/ttyS0; \ + chroot /target /sbin/ifconfig $(/sbin/ifconfig -a | grep '^[a-z]' | cut -d: -f1 | head -n 1) up; \ + sleep 5; \ + echo "Check network after linkup ..." > /target/dev/ttyS0; \ + ip addr show > /target/dev/ttyS0; \ + echo "Check file /etc/apt/sources.list ..." > /target/dev/ttyS0; \ + cat /target/etc/apt/sources.list > /target/dev/ttyS0; \ + if [ -f "/target/etc/os-release" ];\ + then\ + echo "Add offical repo ..." > /target/dev/ttyS0;\ + codename=$(cat /target/etc/os-release | grep PARDUS_CODENAME | cut -d= -f2);\ + echo "deb http://depo.pardus.org.tr/pardus $codename main contrib non-free" >> /target/etc/apt/sources.list;\ + echo "deb http://depo.pardus.org.tr/guvenlik $codename main contrib non-free" >> /target/etc/apt/sources.list;\ + cat /target/etc/apt/sources.list > /target/dev/ttyS0;\ + fi; \ + echo "Update repository ..." > /target/dev/ttyS0; \ + chroot /target apt-get update -y > /dev/ttyS0; \ + echo "Install openssh-server ..." > /target/dev/ttyS0; \ + chroot /target apt-get install -y --no-upgrade openssh-server > /dev/ttyS0; \ + echo "Install packages ..." > /target/dev/ttyS0; \ + chroot /target apt-get install -y --force-yes build-essential open-vm-tools sg3-utils vim > /dev/ttyS0; \ + if [ -f "/target/usr/bin/Xorg" ];\ + then\ + echo "Install package open-vm-tools-desktop ..." > /target/dev/ttyS0;\ + chroot /target apt-get install -y open-vm-tools-desktop > /target/dev/ttyS0;\ + fi; \ + {% if new_user is defined and new_user != 'root' %} + echo '{{ new_user }} ALL=(ALL) NOPASSWD:ALL' >/target/etc/sudoers.d/{{ new_user }}; \ + mkdir -p -m 700 /target/home/{{ new_user }}/.ssh; \ + echo "{{ ssh_public_key }}" > /target/home/{{ new_user }}/.ssh/authorized_keys; \ + {% endif %} + mkdir -p -m 700 /target/root/.ssh; \ + echo "{{ ssh_public_key }}" > /target/root/.ssh/authorized_keys; \ + chown --recursive root:root /target/root/.ssh; \ + chmod 0644 /target/root/.ssh/authorized_keys; \ + echo "Config sshd to enable root login ..." > /target/dev/ttyS0; \ + touch /target/etc/ssh/sshd_config.d/root.conf; \ + echo "PasswordAuthentication yes" >> /target/etc/ssh/sshd_config.d/root.conf; \ + echo "PermitRootLogin yes" >> /target/etc/ssh/sshd_config.d/root.conf; \ + echo "{{ autoinstall_complete_msg }}" > /target/dev/ttyS0 diff --git a/autoinstall/README.md b/autoinstall/README.md index d140c1f3d..f190b1adf 100644 --- a/autoinstall/README.md +++ b/autoinstall/README.md @@ -18,6 +18,7 @@ 17. For UnionTech OS Server 20 1050e unattend auto-install, please use file UOS/Server/20/1050e/ks.cfg. 18. For Fedora Server 36 or later unattend auto-install, please use file Fedora/36/Server/ks.cfg. 19. For FreeBSD 13 or later unattend auto-install, please use file FreeBSD/installerconfig. +20. For Pardus 21.2 Server and XFCE Desktop or later unattend auto-install, please use file Pardus/preseed.cfg. # Notes ## For Windows diff --git a/common/test_rescue.yml b/common/test_rescue.yml index 30a9e0c71..8ff56e5e9 100644 --- a/common/test_rescue.yml +++ b/common/test_rescue.yml @@ -66,7 +66,6 @@ - vm_dir_name - vm_serial_port_output_file is defined - vm_serial_port_output_file - - guest_id is match('freebsd') - name: "Take a snapshot at VM current state" include_tasks: vm_take_snapshot.yml diff --git a/linux/deploy_vm/create_unattend_install_iso.yml b/linux/deploy_vm/create_unattend_install_iso.yml index 80b3e6606..5628f7fe3 100644 --- a/linux/deploy_vm/create_unattend_install_iso.yml +++ b/linux/deploy_vm/create_unattend_install_iso.yml @@ -65,6 +65,7 @@ - unattend_install_conf is not match('Debian') - unattend_install_conf is not match('Ubuntu/Desktop/Ubiquity') - unattend_install_conf is not match('FreeBSD') + - unattend_install_conf is not match('Pardus') - name: "Build unattend install config file into OS ISO image" include_tasks: rebuild_unattend_install_iso.yml @@ -74,7 +75,8 @@ unattend_install_conf is match('Photon') or unattend_install_conf is match('Debian') or unattend_install_conf is match('Ubuntu/Desktop/Ubiquity') or - unattend_install_conf is match('FreeBSD') + unattend_install_conf is match('FreeBSD') or + unattend_install_conf is match('Pardus') when: - unattend_install_conf is not match('Ubuntu/Server/') - unattend_install_conf is not match('Ubuntu/Desktop/Subiquity') @@ -143,6 +145,7 @@ - unattend_install_conf is not match('Debian') - unattend_install_conf is not match('Ubuntu/Desktop/Ubiquity') - unattend_install_conf is not match('FreeBSD') + - unattend_install_conf is not match('Pardus') - name: "Replace original install ISO file with unattend install ISO file" ansible.builtin.set_fact: @@ -152,7 +155,8 @@ unattend_install_conf is match('Photon') or unattend_install_conf is match('Debian') or unattend_install_conf is match('Ubuntu/Desktop/Ubiquity') or - unattend_install_conf is match('FreeBSD') + unattend_install_conf is match('FreeBSD') or + unattend_install_conf is match('Pardus') - name: "Copy generated unattend install config file to log folder" ansible.builtin.copy: diff --git a/linux/deploy_vm/deploy_vm_from_iso.yml b/linux/deploy_vm/deploy_vm_from_iso.yml index 1ebfae5d1..e92a8b9b7 100644 --- a/linux/deploy_vm/deploy_vm_from_iso.yml +++ b/linux/deploy_vm/deploy_vm_from_iso.yml @@ -267,6 +267,19 @@ cdrom_controller_num: "{{ vm_cdroms[0].controller_number | int }}" cdrom_unit_num: "{{ vm_cdroms[0].unit_number | int }}" 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 - include_tasks: ../../common/vm_remove_serial_port.yml diff --git a/linux/deploy_vm/rebuild_debian_unattend_install_iso.yml b/linux/deploy_vm/rebuild_debian_unattend_install_iso.yml new file mode 100644 index 000000000..fa4d0d660 --- /dev/null +++ b/linux/deploy_vm/rebuild_debian_unattend_install_iso.yml @@ -0,0 +1,95 @@ +# Copyright 2023 VMware, Inc. +# SPDX-License-Identifier: BSD-2-Clause +--- +# Rebuild Debian ISO image with unattended install file +# Parameters: +# rebuilt_unattend_iso_path: Local path to the rebuilt ISO image with unattend install config file +# src_iso_file_path: Local path of source ISO image file +# src_iso_file_dir: Local dir of source ISO image file +# +- name: "Extract specific files inside ISO" + community.general.iso_extract: + image: "{{ src_iso_file_path }}" + dest: "{{ src_iso_file_dir }}" + files: + - 'boot/grub/grub.cfg' + - 'isolinux/isolinux.cfg' + - 'isolinux/gtk.cfg' + - 'md5sum.txt' + +- name: "Update timeout for boot menu" + ansible.builtin.replace: + path: "{{ src_iso_file_dir }}/isolinux.cfg" + regexp: "timeout 0" + replace: "timeout 1" + +- name: "Search string in md5sum.txt" + ansible.builtin.shell: grep '/install.386/' {{ src_iso_file_dir }}/md5sum.txt + ignore_errors: true + register: result_search_str + +- name: "Print the result of searching str in file md5sum.txt" + ansible.builtin.debug: var=result_search_str + +- name: "Set fact of Debian install type" + ansible.builtin.set_fact: + debian_install_type: |- + {%- if result_search_str.failed -%}install.amd + {%- else -%}install.386 + {%- endif -%} + +- debug: var=debian_install_type + +- name: "Update timeout for boot menu" + ansible.builtin.replace: + path: "{{ src_iso_file_dir }}/isolinux.cfg" + regexp: "default .*" + replace: "default installgui" + +- name: "Update Debian grub.cfg for autoinstall" + ansible.builtin.blockinfile: + path: "{{ src_iso_file_dir }}/grub.cfg" + block: | + set default="autoinstall" + set timeout=5 + menuentry "Automated installation" --id autoinstall { + set background_color=black + linux /{{ debian_install_type }}/vmlinuz auto=true file=/cdrom/{{ unattend_install_file_name }} vga=788 --- quiet + initrd /{{ debian_install_type }}/gtk/initrd.gz + } + +- name: "Update boot menu with preseed.cfg for Debian" + ansible.builtin.replace: + path: "{{ src_iso_file_dir }}/gtk.cfg" + regexp: '(.*)(initrd.gz )(.*)' + replace: "\\1\\2 auto=true file=/cdrom/{{ unattend_install_file_name }} \\3" + +- name: "Update md5sum for Debian ISO files" + ansible.builtin.shell: "{{ item }}" + with_items: + - "sed -i '#./isolinux/isolinux.cfg#d' md5sum.txt" + - "echo \"`md5sum isolinux.cfg | awk '{print $1}'` ./isolinux/isolinux.cfg\" >>md5sum.txt" + - "sed -i '#./boot/grub/grub.cfg#d' md5sum.txt" + - "echo \"`md5sum grub.cfg | awk '{print $1}'` ./boot/grub/grub.cfg\" >>md5sum.txt" + args: + chdir: "{{ src_iso_file_dir }}" + register: update_initrd_output + +- name: "Print command output for updating initrd" + ansible.builtin.debug: var=update_initrd_output + +- name: "Customize the ISO" + community.general.iso_customize: + src_iso: "{{ src_iso_file_path }}" + dest_iso: "{{ rebuilt_unattend_iso_path }}" + add_files: + - src_file: "{{ src_iso_file_dir }}/grub.cfg" + dest_file: "boot/grub/grub.cfg" + - src_file: "{{ src_iso_file_dir }}/isolinux.cfg" + dest_file: "isolinux/isolinux.cfg" + - src_file: "{{ src_iso_file_dir }}/gtk.cfg" + dest_file: "isolinux/gtk.cfg" + - src_file: "{{ src_iso_file_dir }}/md5sum.txt" + dest_file: "md5sum.txt" + - src_file: "{{ new_unattend_install_conf }}" + dest_file: "{{ unattend_install_file_name }}" diff --git a/linux/deploy_vm/rebuild_pardus_unattend_install_iso.yml b/linux/deploy_vm/rebuild_pardus_unattend_install_iso.yml new file mode 100644 index 000000000..dfedea7bc --- /dev/null +++ b/linux/deploy_vm/rebuild_pardus_unattend_install_iso.yml @@ -0,0 +1,110 @@ +# Copyright 2023 VMware, Inc. +# SPDX-License-Identifier: BSD-2-Clause +--- +# Rebuild Pardus ISO image with unattended install file +# Parameters: +# rebuilt_unattend_iso_path: Local path to the rebuilt ISO image with unattend install config file +# src_iso_file_path: Local path of source ISO image file +# src_iso_file_dir: Local dir of source ISO image file +# +- name: "Extract specific files inside ISO" + community.general.iso_extract: + image: "{{ src_iso_file_path }}" + dest: "{{ src_iso_file_dir }}" + files: + - 'boot/grub/grub.cfg' + - 'isolinux/isolinux.cfg' + - 'isolinux/install_en.cfg' + - 'isolinux/install.cfg' + - 'md5sum.txt' + +- name: "Update timeout of file isolinux.cfg" + ansible.builtin.replace: + path: "{{ src_iso_file_dir }}/isolinux.cfg" + regexp: "timeout 0" + replace: "timeout 1" + +- name: "Update file isolinux.cfg" + ansible.builtin.replace: + path: "{{ src_iso_file_dir }}/isolinux.cfg" + regexp: "default .*" + replace: "default installgui" + +- name: "Update default boot label" + ansible.builtin.lineinfile: + path: "{{ src_iso_file_dir }}/{{ item }}" + insertbefore: "^label install$" + line: "default installgui" + with_items: + - "install_en.cfg" + - "install.cfg" + +- name: "Update boot parameters with preseed.cfg" + ansible.builtin.replace: + path: "{{ src_iso_file_dir }}/{{ item }}" + regexp: '(.*)(append )(.*)' + replace: "\\1\\2 auto=true file=/cdrom/{{ unattend_install_file_name }} \\3" + with_items: + - "install_en.cfg" + - "install.cfg" + +- name: "Update default memuentry for grub.cfg" + ansible.builtin.replace: + path: "{{ src_iso_file_dir }}/grub.cfg" + regexp: "set default=0" + replace: "set default=1\nset timeout=3" + +- name: "Update default boot entry for autoinstall" + ansible.builtin.lineinfile: + path: "{{ src_iso_file_dir }}/grub.cfg" + insertafter: "^submenu.*English.*{#" + line: ' set default="autoinstall"' + +- name: "Update boot parameters for autoinstall" + ansible.builtin.blockinfile: + path: "{{ src_iso_file_dir }}/grub.cfg" + insertafter: ".*autoinstall.*" + block: | + # menuentry for unattended installation + menuentry "Automated installation" --id autoinstall { + set background_color=black + linux /install/gtk/vmlinuz auto=true file=/cdrom/{{ unattend_install_file_name }} video=vesa:ywrap,mtrr vga=788 --- quiet + initrd /install/gtk/initrd.gz + } + +- name: "Update md5sum for Pardus ISO files" + ansible.builtin.shell: "{{ item }}" + with_items: + - "sed -i '#./isolinux/isolinux.cfg#d' md5sum.txt" + - "echo \"`md5sum isolinux.cfg | awk '{print $1}'` ./isolinux/isolinux.cfg\" >>md5sum.txt" + - "sed -i '#./boot/grub/grub.cfg#d' md5sum.txt" + - "echo \"`md5sum grub.cfg | awk '{print $1}'` ./boot/grub/grub.cfg\" >>md5sum.txt" + - "sed -i '#./isolinux/install_en.cfg#d' md5sum.txt" + - "echo \"`md5sum install_en.cfg | awk '{print $1}'` ./isolinux/install_en.cfg\" >>md5sum.txt" + - "sed -i '#./isolinux/install.cfg#d' md5sum.txt" + - "echo \"`md5sum install.cfg | awk '{print $1}'` ./isolinux/install.cfg\" >>md5sum.txt" + args: + chdir: "{{ src_iso_file_dir }}" + register: update_initrd_output + +- name: "Print command output for updating initrd" + ansible.builtin.debug: var=update_initrd_output + +- name: "Customize the ISO" + community.general.iso_customize: + src_iso: "{{ src_iso_file_path }}" + dest_iso: "{{ rebuilt_unattend_iso_path }}" + add_files: + - src_file: "{{ src_iso_file_dir }}/grub.cfg" + dest_file: "boot/grub/grub.cfg" + - src_file: "{{ src_iso_file_dir }}/isolinux.cfg" + dest_file: "isolinux/isolinux.cfg" + - src_file: "{{ src_iso_file_dir }}/install_en.cfg" + dest_file: "isolinux/install_en.cfg" + - src_file: "{{ src_iso_file_dir }}/install.cfg" + dest_file: "isolinux/install.cfg" + - src_file: "{{ src_iso_file_dir }}/md5sum.txt" + dest_file: "md5sum.txt" + - src_file: "{{ new_unattend_install_conf }}" + dest_file: "{{ unattend_install_file_name }}" + diff --git a/linux/deploy_vm/rebuild_photon_unattend_install_iso.yml b/linux/deploy_vm/rebuild_photon_unattend_install_iso.yml new file mode 100644 index 000000000..f51f5ac53 --- /dev/null +++ b/linux/deploy_vm/rebuild_photon_unattend_install_iso.yml @@ -0,0 +1,46 @@ +# Copyright 2023 VMware, Inc. +# SPDX-License-Identifier: BSD-2-Clause +--- +# Rebuild Photon ISO image with unattended install file +# Parameters: +# rebuilt_unattend_iso_path: Local path to the rebuilt ISO image with unattend install config file +# src_iso_file_path: Local path of source ISO image file +# src_iso_file_dir: Local dir of source ISO image file +# +- name: "Extract specific files inside ISO" + community.general.iso_extract: + image: "{{ src_iso_file_path }}" + dest: "{{ src_iso_file_dir }}" + files: + - 'boot/grub2/grub.cfg' + - 'isolinux/isolinux.cfg' + - 'isolinux/menu.cfg' + +- name: "Update timeout for boot menu" + ansible.builtin.replace: + path: "{{ src_iso_file_dir }}/isolinux.cfg" + regexp: "timeout 0" + replace: "timeout 1" + +- name: "Update boot menu with kickstart for VMware Photon OS" + ansible.builtin.replace: + path: "{{ src_iso_file_dir }}/{{ item }}" + regexp: '(.*)(root=[^ ]+)(.*)' + replace: "\\1\\2 ks=cdrom:/isolinux/{{ unattend_install_file_name }} \\3" + with_items: + - "menu.cfg" + - "grub.cfg" + +- name: "Customize the ISO" + community.general.iso_customize: + src_iso: "{{ src_iso_file_path }}" + dest_iso: "{{ rebuilt_unattend_iso_path }}" + add_files: + - src_file: "{{ src_iso_file_dir }}/menu.cfg" + dest_file: "isolinux/menu.cfg" + - src_file: "{{ src_iso_file_dir }}/grub.cfg" + dest_file: "boot/grub2/grub.cfg" + - src_file: "{{ src_iso_file_dir }}/isolinux.cfg" + dest_file: "isolinux/isolinux.cfg" + - src_file: "{{ new_unattend_install_conf }}" + dest_file: "isolinux/{{ unattend_install_file_name }}" diff --git a/linux/deploy_vm/rebuild_ubuntu_unattend_install_iso.yml b/linux/deploy_vm/rebuild_ubuntu_unattend_install_iso.yml new file mode 100644 index 000000000..b45fe9455 --- /dev/null +++ b/linux/deploy_vm/rebuild_ubuntu_unattend_install_iso.yml @@ -0,0 +1,179 @@ +# Copyright 2023 VMware, Inc. +# SPDX-License-Identifier: BSD-2-Clause +--- +# Rebuild Ubuntu ISO image with unattended install file +# Parameters: +# rebuilt_unattend_iso_path: Local path to the rebuilt ISO image with unattend install config file +# src_iso_file_path: Local path of source ISO image file +# src_iso_file_dir: Local dir of source ISO image file +# +- name: "Rebuild ISO for Ubuntu 20.04 ~ 22.10 desktop" + block: + - name: "Extract specific files inside ISO" + community.general.iso_extract: + image: "{{ src_iso_file_path }}" + dest: "{{ src_iso_file_dir }}" + files: + - "boot/grub/grub.cfg" + + - name: "Modify boot entry" + ansible.builtin.replace: + path: "{{ src_iso_file_dir }}/grub.cfg" + regexp: "set timeout=[1-9][0-9]{0,1}" + replace: "default=0\nset timeout=2" + + - name: "Modify boot options" + ansible.builtin.replace: + path: "{{ src_iso_file_dir }}/grub.cfg" + regexp: "file=/cdrom/preseed/ubuntu.seed maybe-ubiquity quiet splash ---" + replace: "file=/cdrom/preseed/ubuntu.seed boot=casper debug-ubiquity automatic-ubiquity quiet splash noprompt --- console=ttyS0,115200n8" + + - name: "Print the content of modified file grub.cfg" + ansible.builtin.debug: + msg: "{{ lookup('file', src_iso_file_dir + '/grub.cfg') }}" + + - name: "Extract isolinux/isolinux.cfg inside ISO for old releases" + community.general.iso_extract: + image: "{{ src_iso_file_path }}" + dest: "{{ src_iso_file_dir }}" + files: + - "isolinux/isolinux.cfg" + ignore_errors: true + register: result_extract_file + + - name: "Modify isolinux.cfg for some old releases such as Ubuntu 20.04 when the firmware is bios" + block: + - name: "Modify boot option" + ansible.builtin.blockinfile: + path: "{{ src_iso_file_dir }}/isolinux.cfg" + insertafter: "^#.*etc.*" + block: | + default live-install + label live-install + menu label ^Install Ubuntu + kernel /casper/vmlinuz + append file=/cdrom/preseed/ubuntu.seed boot=casper debug-ubiquity automatic-ubiquity initrd=/casper/initrd quiet splash noprompt --- console=ttyS0,115200n8 + + - name: "Print the content of modified file isolinux.cfg" + ansible.builtin.debug: + msg: "{{ lookup('file', src_iso_file_dir + '/isolinux.cfg') }}" + + - name: "Customize the ISO with isolinux/isolinux.cfg" + community.general.iso_customize: + src_iso: "{{ src_iso_file_path }}" + dest_iso: "{{ rebuilt_unattend_iso_path }}" + add_files: + - src_file: "{{ src_iso_file_dir }}/grub.cfg" + dest_file: "/boot/grub/grub.cfg" + - src_file: "{{ new_unattend_install_conf }}" + dest_file: "/preseed/ubuntu.seed" + - src_file: "{{ src_iso_file_dir }}/isolinux.cfg" + dest_file: "/isolinux/isolinux.cfg" + when: + - result_extract_file is defined + - result_extract_file.failed is defined + - not result_extract_file.failed + + - name: "Customize the ISO without isolinux/isolinux.cfg" + community.general.iso_customize: + src_iso: "{{ src_iso_file_path }}" + dest_iso: "{{ rebuilt_unattend_iso_path }}" + add_files: + - src_file: "{{ src_iso_file_dir }}/grub.cfg" + dest_file: "/boot/grub/grub.cfg" + - src_file: "{{ new_unattend_install_conf }}" + dest_file: "/preseed/ubuntu.seed" + when: + - result_extract_file is defined + - result_extract_file.failed is defined + - result_extract_file.failed + when: unattend_install_conf is match('Ubuntu/Desktop/Ubiquity') + +- name: "Rebuild ISO for Ubuntu live server / Ubuntu 23.04 or later Desktop" + block: + - name: Extract specific files inside ISO + community.general.iso_extract: + image: "{{ src_iso_file_path }}" + dest: "{{ src_iso_file_dir }}" + files: + - 'boot/grub/grub.cfg' + - 'md5sum.txt' + + - name: "Add autoinstall to UEFI boot kernel command for Ubuntu live server" + ansible.builtin.replace: + path: "{{ unattend_iso_cache }}/grub.cfg" + regexp: '(.*vmlinuz)(.*)' + replace: "\\1 autoinstall \\2" + + - name: "Set timeout to 5 seconds at boot menu" + ansible.builtin.replace: + path: "{{ unattend_iso_cache }}/grub.cfg" + regexp: 'set timeout=.*' + replace: "set timeout=5" + + - name: "Update md5sum for UEFI boot config file" + ansible.builtin.shell: | + md5=`md5sum grub.cfg | awk '{print $1}'` + sed -i "/.\/boot\/grub\/grub.cfg/ s/^[^ ]*/$md5/" md5sum.txt + args: + chdir: "{{ unattend_iso_cache }}" + + - name: "set var ubuntu_bios_cfg_exist to default false" + ansible.builtin.set_fact: + ubuntu_bios_cfg_exist: false + + - name: "Extract isolinux/txt.cfg inside ISO if exists" + community.general.iso_extract: + image: "{{ src_iso_file_path }}" + dest: "{{ src_iso_file_dir }}" + files: + - 'isolinux/txt.cfg' + register: check_file_result + ignore_errors: true + + - debug: var=check_file_result + + - name: "set var ubuntu_bios_cfg_exist to true or not" + ansible.builtin.set_fact: + ubuntu_bios_cfg_exist: true + when: not check_file_result.failed + + - name: "Update BIOS boot config file if it exists and Customize ISO" + block: + - name: "Add autoinstall to BIOS boot kernel command for Ubuntu live server" + ansible.builtin.replace: + path: "{{ unattend_iso_cache }}/txt.cfg" + regexp: '(.*initrd)(.*)' + replace: "\\1 autoinstall \\2" + + - name: "Update md5sum for BIOS boot config file" + ansible.builtin.shell: | + md5=`md5sum txt.cfg | awk '{print $1}'` + sed -i "/.\/isolinux\/txt.cfg/ s/^[^ ]*/$md5/" md5sum.txt + args: + chdir: "{{ unattend_iso_cache }}" + + - name: "Customize the ISO" + community.general.iso_customize: + src_iso: "{{ src_iso_file_path }}" + dest_iso: "{{ rebuilt_unattend_iso_path }}" + add_files: + - src_file: "{{ src_iso_file_dir }}/grub.cfg" + dest_file: "boot/grub/grub.cfg" + - src_file: "{{ src_iso_file_dir }}/md5sum.txt" + dest_file: "md5sum.txt" + - src_file: "{{ src_iso_file_dir }}/txt.cfg" + dest_file: "isolinux/txt.cfg" + when: ubuntu_bios_cfg_exist + + - name: "Customize the ISO without txt.cfg" + community.general.iso_customize: + src_iso: "{{ src_iso_file_path }}" + dest_iso: "{{ rebuilt_unattend_iso_path }}" + add_files: + - src_file: "{{ src_iso_file_dir }}/grub.cfg" + dest_file: "boot/grub/grub.cfg" + - 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') diff --git a/linux/deploy_vm/rebuild_unattend_install_iso.yml b/linux/deploy_vm/rebuild_unattend_install_iso.yml index 4ee6cbb35..82ab7192e 100644 --- a/linux/deploy_vm/rebuild_unattend_install_iso.yml +++ b/linux/deploy_vm/rebuild_unattend_install_iso.yml @@ -28,308 +28,13 @@ ansible.builtin.set_fact: unattend_install_file_name: "{{ new_unattend_install_conf | basename }}" -- name: "Rebuild ISO for Ubuntu 20.04 ~ 22.10 desktop" - block: - - name: "Extract specific files inside ISO" - community.general.iso_extract: - image: "{{ src_iso_file_path }}" - dest: "{{ src_iso_file_dir }}" - files: - - "boot/grub/grub.cfg" - - - name: "Modify boot entry" - ansible.builtin.replace: - path: "{{ src_iso_file_dir }}/grub.cfg" - regexp: "set timeout=[1-9][0-9]{0,1}" - replace: "default=0\nset timeout=2" - - - name: "Modify boot options" - ansible.builtin.replace: - path: "{{ src_iso_file_dir }}/grub.cfg" - regexp: "file=/cdrom/preseed/ubuntu.seed maybe-ubiquity quiet splash ---" - replace: "file=/cdrom/preseed/ubuntu.seed boot=casper debug-ubiquity automatic-ubiquity quiet splash noprompt --- console=ttyS0,115200n8" - - - name: "Print the content of modified file grub.cfg" - ansible.builtin.debug: - msg: "{{ lookup('file', src_iso_file_dir + '/grub.cfg') }}" - - - name: "Extract isolinux/isolinux.cfg inside ISO for old releases" - community.general.iso_extract: - image: "{{ src_iso_file_path }}" - dest: "{{ src_iso_file_dir }}" - files: - - "isolinux/isolinux.cfg" - ignore_errors: true - register: result_extract_file - - - name: "Modify isolinux.cfg for some old releases such as Ubuntu 20.04 when the firmware is bios" - block: - - name: "Modify boot option" - ansible.builtin.blockinfile: - path: "{{ src_iso_file_dir }}/isolinux.cfg" - insertafter: "^#.*etc.*" - block: | - default live-install - label live-install - menu label ^Install Ubuntu - kernel /casper/vmlinuz - append file=/cdrom/preseed/ubuntu.seed boot=casper debug-ubiquity automatic-ubiquity initrd=/casper/initrd quiet splash noprompt --- console=ttyS0,115200n8 - - - name: "Print the content of modified file isolinux.cfg" - ansible.builtin.debug: - msg: "{{ lookup('file', src_iso_file_dir + '/isolinux.cfg') }}" - - - name: "Customize the ISO with isolinux/isolinux.cfg" - community.general.iso_customize: - src_iso: "{{ src_iso_file_path }}" - dest_iso: "{{ rebuilt_unattend_iso_path }}" - add_files: - - src_file: "{{ src_iso_file_dir }}/grub.cfg" - dest_file: "/boot/grub/grub.cfg" - - src_file: "{{ new_unattend_install_conf }}" - dest_file: "/preseed/ubuntu.seed" - - src_file: "{{ src_iso_file_dir }}/isolinux.cfg" - dest_file: "/isolinux/isolinux.cfg" - when: - - result_extract_file is defined - - result_extract_file.failed is defined - - not result_extract_file.failed - - - name: "Customize the ISO without isolinux/isolinux.cfg" - community.general.iso_customize: - src_iso: "{{ src_iso_file_path }}" - dest_iso: "{{ rebuilt_unattend_iso_path }}" - add_files: - - src_file: "{{ src_iso_file_dir }}/grub.cfg" - dest_file: "/boot/grub/grub.cfg" - - src_file: "{{ new_unattend_install_conf }}" - dest_file: "/preseed/ubuntu.seed" - when: - - result_extract_file is defined - - result_extract_file.failed is defined - - result_extract_file.failed - when: unattend_install_conf is match('Ubuntu/Desktop/Ubiquity') - -- name: "Rebuild ISO for Photon" - block: - - name: "Extract specific files inside ISO" - community.general.iso_extract: - image: "{{ src_iso_file_path }}" - dest: "{{ src_iso_file_dir }}" - files: - - 'boot/grub2/grub.cfg' - - 'isolinux/isolinux.cfg' - - 'isolinux/menu.cfg' - - - name: "Update timeout for boot menu" - ansible.builtin.replace: - path: "{{ src_iso_file_dir }}/isolinux.cfg" - regexp: "timeout 0" - replace: "timeout 1" - - - name: "Update boot menu with kickstart for VMware Photon OS" - ansible.builtin.replace: - path: "{{ src_iso_file_dir }}/{{ item }}" - regexp: '(.*)(root=[^ ]+)(.*)' - replace: "\\1\\2 ks=cdrom:/isolinux/{{ unattend_install_file_name }} \\3" - with_items: - - "menu.cfg" - - "grub.cfg" - - - name: "Customize the ISO" - community.general.iso_customize: - src_iso: "{{ src_iso_file_path }}" - dest_iso: "{{ rebuilt_unattend_iso_path }}" - add_files: - - src_file: "{{ src_iso_file_dir }}/menu.cfg" - dest_file: "isolinux/menu.cfg" - - src_file: "{{ src_iso_file_dir }}/grub.cfg" - dest_file: "boot/grub2/grub.cfg" - - src_file: "{{ src_iso_file_dir }}/isolinux.cfg" - dest_file: "isolinux/isolinux.cfg" - - src_file: "{{ new_unattend_install_conf }}" - dest_file: "isolinux/{{ unattend_install_file_name }}" - when: unattend_install_conf is match('Photon') - -- name: "Rebuild ISO for Debian" - block: - - name: "Extract specific files inside ISO" - community.general.iso_extract: - image: "{{ src_iso_file_path }}" - dest: "{{ src_iso_file_dir }}" - files: - - 'boot/grub/grub.cfg' - - 'isolinux/isolinux.cfg' - - 'isolinux/gtk.cfg' - - 'md5sum.txt' - - - name: "Update timeout for boot menu" - ansible.builtin.replace: - path: "{{ src_iso_file_dir }}/isolinux.cfg" - regexp: "timeout 0" - replace: "timeout 1" - - - name: "Search string in md5sum.txt" - ansible.builtin.shell: grep '/install.386/' {{ src_iso_file_dir }}/md5sum.txt - ignore_errors: true - register: result_search_str - - - name: "Print the result of searching str in file md5sum.txt" - ansible.builtin.debug: var=result_search_str - - - name: "Set fact of Debian install type" - ansible.builtin.set_fact: - debian_install_type: |- - {%- if result_search_str.failed -%}install.amd - {%- else -%}install.386 - {%- endif -%} - - - debug: var=debian_install_type - - - name: "Update timeout for boot menu" - ansible.builtin.replace: - path: "{{ src_iso_file_dir }}/isolinux.cfg" - regexp: "default .*" - replace: "default installgui" - - - name: "Update Debian grub.cfg for autoinstall" - ansible.builtin.blockinfile: - path: "{{ src_iso_file_dir }}/grub.cfg" - block: | - set default="autoinstall" - set timeout=5 - menuentry "Automated installation" --id autoinstall { - set background_color=black - linux /{{ debian_install_type }}/vmlinuz auto=true file=/cdrom/{{ unattend_install_file_name }} vga=788 --- quiet - initrd /{{ debian_install_type }}/gtk/initrd.gz - } - - - name: "Update boot menu with preseed.cfg for Debian" - ansible.builtin.replace: - path: "{{ src_iso_file_dir }}/gtk.cfg" - regexp: '(.*)(initrd.gz )(.*)' - replace: "\\1\\2 auto=true file=/cdrom/{{ unattend_install_file_name }} \\3" - - - name: "Update md5sum for Debian ISO files" - ansible.builtin.shell: "{{ item }}" - with_items: - - "sed -i '#./isolinux/isolinux.cfg#d' md5sum.txt" - - "echo \"`md5sum isolinux.cfg | awk '{print $1}'` ./isolinux/isolinux.cfg\" >>md5sum.txt" - - "sed -i '#./boot/grub/grub.cfg#d' md5sum.txt" - - "echo \"`md5sum grub.cfg | awk '{print $1}'` ./boot/grub/grub.cfg\" >>md5sum.txt" - args: - chdir: "{{ src_iso_file_dir }}" - register: update_initrd_output - - - name: "Print command output for updating initrd" - ansible.builtin.debug: var=update_initrd_output - - - name: "Customize the ISO" - community.general.iso_customize: - src_iso: "{{ src_iso_file_path }}" - dest_iso: "{{ rebuilt_unattend_iso_path }}" - add_files: - - src_file: "{{ src_iso_file_dir }}/grub.cfg" - dest_file: "boot/grub/grub.cfg" - - src_file: "{{ src_iso_file_dir }}/isolinux.cfg" - dest_file: "isolinux/isolinux.cfg" - - src_file: "{{ src_iso_file_dir }}/gtk.cfg" - dest_file: "isolinux/gtk.cfg" - - src_file: "{{ src_iso_file_dir }}/md5sum.txt" - dest_file: "md5sum.txt" - - src_file: "{{ new_unattend_install_conf }}" - dest_file: "{{ unattend_install_file_name }}" - when: unattend_install_conf is match('Debian') - -- name: "Rebuild ISO for Ubuntu live server" - block: - - name: Extract specific files inside ISO - community.general.iso_extract: - image: "{{ src_iso_file_path }}" - dest: "{{ src_iso_file_dir }}" - files: - - 'boot/grub/grub.cfg' - - 'md5sum.txt' - - - name: "Add autoinstall to UEFI boot kernel command for Ubuntu live server" - ansible.builtin.replace: - path: "{{ unattend_iso_cache }}/grub.cfg" - regexp: '(.*vmlinuz)(.*)' - replace: "\\1 autoinstall \\2" - when: unattend_install_conf is match('Ubuntu/Server') or unattend_install_conf is match('Ubuntu/Desktop/Subiquity') - - - name: "Set timeout to 5 seconds at boot menu" - ansible.builtin.replace: - path: "{{ unattend_iso_cache }}/grub.cfg" - regexp: 'set timeout=.*' - replace: "set timeout=5" - - - name: "Update md5sum for UEFI boot config file" - ansible.builtin.shell: | - md5=`md5sum grub.cfg | awk '{print $1}'` - sed -i "/.\/boot\/grub\/grub.cfg/ s/^[^ ]*/$md5/" md5sum.txt - args: - chdir: "{{ unattend_iso_cache }}" - - - name: "set var ubuntu_bios_cfg_exist to default false" - ansible.builtin.set_fact: - ubuntu_bios_cfg_exist: false - - - name: "Extract isolinux/txt.cfg inside ISO if exists" - community.general.iso_extract: - image: "{{ src_iso_file_path }}" - dest: "{{ src_iso_file_dir }}" - files: - - 'isolinux/txt.cfg' - register: check_file_result - ignore_errors: true - - - debug: var=check_file_result - - - name: "set var ubuntu_bios_cfg_exist to true or not" - ansible.builtin.set_fact: - ubuntu_bios_cfg_exist: true - when: not check_file_result.failed - - - name: "Update BIOS boot config file if it exists and Customize ISO" - block: - - name: "Add autoinstall to BIOS boot kernel command for Ubuntu live server" - ansible.builtin.replace: - path: "{{ unattend_iso_cache }}/txt.cfg" - regexp: '(.*initrd)(.*)' - replace: "\\1 autoinstall \\2" - - - name: "Update md5sum for BIOS boot config file" - ansible.builtin.shell: | - md5=`md5sum txt.cfg | awk '{print $1}'` - sed -i "/.\/isolinux\/txt.cfg/ s/^[^ ]*/$md5/" md5sum.txt - args: - chdir: "{{ unattend_iso_cache }}" - - - name: "Customize the ISO" - community.general.iso_customize: - src_iso: "{{ src_iso_file_path }}" - dest_iso: "{{ rebuilt_unattend_iso_path }}" - add_files: - - src_file: "{{ src_iso_file_dir }}/grub.cfg" - dest_file: "boot/grub/grub.cfg" - - src_file: "{{ src_iso_file_dir }}/md5sum.txt" - dest_file: "md5sum.txt" - - src_file: "{{ src_iso_file_dir }}/txt.cfg" - dest_file: "isolinux/txt.cfg" - when: ubuntu_bios_cfg_exist +- name: "Set fact of unattend install config file name" + ansible.builtin.set_fact: + unattend_install_os_type: "{{ unattend_install_conf.split('/')[0] | lower }}" - - name: "Customize the ISO without txt.cfg" - community.general.iso_customize: - src_iso: "{{ src_iso_file_path }}" - dest_iso: "{{ rebuilt_unattend_iso_path }}" - add_files: - - src_file: "{{ src_iso_file_dir }}/grub.cfg" - dest_file: "boot/grub/grub.cfg" - - 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') +- name: "rebuild ISO for {{ unattend_install_os_type }}" + include_tasks: "rebuild_{{ unattend_install_os_type }}_unattend_install_iso.yml" + when: unattend_install_os_type in ["photon", "debian", "ubuntu", "pardus"] - name: "Rebuild ISO for FreeBSD" community.general.iso_customize: @@ -338,4 +43,4 @@ add_files: - src_file: "{{ new_unattend_install_conf }}" dest_file: "/etc/installerconfig" - when: unattend_install_conf is match('FreeBSD') + when: unattend_install_os_type == "freebsd"