Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
Winnie81 committed Mar 28, 2023
2 parents 01b7472 + 4949862 commit 09a41bc
Show file tree
Hide file tree
Showing 11 changed files with 285 additions and 33 deletions.
140 changes: 140 additions & 0 deletions autoinstall/FreeBSD/installerconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@

debug=yes
nonInteractive=yes

{% if boot_disk_controller == 'nvme' %}
PARTITIONS="nvd0 gpt"
{% elif boot_disk_controller == 'sata' or boot_disk_controller == 'ide' %}
PARTITIONS="ada0 gpt"
{% else %}
PARTITIONS="da0 gpt"
{% endif %}

{% if guest_id.find('64Guest') != -1 %}
DISTRIBUTIONS="kernel.txz base.txz kernel-dbg.txz lib32.txz src.txz ports.txz"
{% else %}
DISTRIBUTIONS="kernel.txz base.txz kernel-dbg.txz src.txz ports.txz"
{% endif %}

#!/bin/sh
# Set hostname
sysrc hostname="FreeBSD-{{ hostname_timestamp }}"

{% if boot_disk_controller == 'nvme' %}
gpart bootcode -b /boot/pmbr -p /boot/gptboot -i 1 nvd0
{% elif boot_disk_controller == 'sata' or boot_disk_controller == 'ide' %}
gpart bootcode -b /boot/pmbr -p /boot/gptboot -i 1 ada0
{% else %}
gpart bootcode -b /boot/pmbr -p /boot/gptboot -i 1 da0
{% endif %}

# Set Time Zone to UTC
echo "Setting Time Zone to UTC ..."
/bin/cp /usr/share/zoneinfo/UTC /etc/localtime
/usr/bin/touch /etc/wall_cmos_clock
/sbin/adjkerntz -a

echo "Set network interface with DHCP IP assignment ..." > /dev/ttyu0
ifdev=$(ifconfig | grep '^[a-z]' | cut -d: -f1 | head -n 1)
echo "Get ifname ${ifdev}" > /dev/ttyu0
sysrc ifconfig_${ifdev}=DHCP

# Get DHCP for nic0
echo "Get IP with dhclient ..." > /dev/ttyu0
dhclient ${ifdev}
sleep 15
echo "Check network ..." > /dev/ttyu0
ifconfig > /dev/ttyu0

# Set Proxy.
{% if http_proxy_vm is defined and http_proxy_vm %}
setenv HTTP_PROXY {{ http_proxy_vm }}
{% endif %}

# Installing packages
echo "Installing packages ..." > /dev/ttyu0
env ASSUME_ALWAYS_YES=YES pkg bootstrap -y

# Hit issue: reset by peer during install packages
# The open-vm-tools is not installed by default
mkdir -p /usr/local/etc/pkg/repos
mount > /dev/ttyu0
cp -rf /dist/packages/repos/FreeBSD_install_cdrom.conf /usr/local/etc/pkg/repos/FreeBSD_install_cdrom.conf
env ASSUME_ALWAYS_YES=YES pkg update -f > /dev/ttyu0

# We install packages from ISO image
# Different packages between the 32bit image and 64bit image
packages_to_install='bash sudo xorg kde5 xf86-video-vmware'
for package_to_install in $packages_to_install
do
echo "Install package $package_to_install (try $try_count time) ..." > /dev/ttyu0
env ASSUME_ALWAYS_YES=YES pkg install -y $package_to_install
ret=$?
if [ $ret == 0 ]
then
echo "Succeed to install the package($package_to_install)" > /dev/ttyu0
else
echo "Failed to install the package($package_to_install)" > /dev/ttyu0
fi
done

# Disable ISO repo and enable default repo
rm -rf /usr/local/etc/pkg/repos/FreeBSD_install_cdrom.conf
env ASSUME_ALWAYS_YES=YES pkg update -f > /dev/ttyu0
packages_to_install='sddm open-vm-tools xf86-input-vmmouse wget curl'
for package_to_install in $packages_to_install
do
ret=1
try_count=1
until [ $ret -eq 0 ]
do
echo "Install package $package_to_install (try $try_count time) ..." > /dev/ttyu0
env ASSUME_ALWAYS_YES=YES pkg install -y $package_to_install
ret=$?
try_count=$((try_count+1))
done
echo "The package($package_to_install) is already installed" > /dev/ttyu0
done

# Add new user.
{% if new_user is defined and new_user != 'root' %}
echo "{{ vm_password }}" | pw useradd {{ new_user }} -s /bin/sh -d /home/{{ new_user }} -m -g wheel -h 0
echo '{{ new_user }} ALL=(ALL:ALL) ALL' >> /usr/local/etc/sudoers
{% endif %}

# Set password of root user
echo "{{ vm_password }}" | pw -V /etc usermod root -h 0

# Enable root login via ssh
echo "Enable root login via ssh ..." > /dev/ttyu0
mkdir -p -m 700 /root/.ssh
echo "{{ ssh_public_key }}" > /root/.ssh/authorized_keys
chown -R root /root/.ssh
chmod 0644 /root/.ssh/authorized_keys
# We can't ssh to VM with empty password for root user
sed -i .bak -e 's/#PasswordAuthentication.*/PasswordAuthentication yes/' /etc/ssh/sshd_config
sed -i '' -e 's/#PermitRootLogin.*/PermitRootLogin yes/' /etc/ssh/sshd_config

# Enable service
echo "Enable service ..." > /dev/ttyu0
sysrc sshd_enable="YES"
sysrc ntpd_enable="YES"
sysrc ntpd_sync_on_start="YES"

# Configure KDE desktop
echo "proc /proc procfs rw 0 0" >> /etc/fstab
sysrc dbus_enable="YES"
sysrc sddm_enable="YES"

# Autologin to desktop environment
echo "[Autologin]" >> /usr/local/etc/sddm.conf
echo "User={{ new_user }}" >> /usr/local/etc/sddm.conf
echo "Session=plasma.desktop" >> /usr/local/etc/sddm.conf

# Reducing boot menu delay
echo "Reducing boot menu delay ..." > /dev/ttyu0
echo 'autoboot_delay="3"' >> /boot/loader.conf

echo "End of installerconfig" > /dev/ttyu0
echo "{{ autoinstall_complete_msg }}" > /dev/ttyu0
shutdown -r now
1 change: 1 addition & 0 deletions autoinstall/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
15. For UnionTech OS Server 20 1050a unattend auto-install, please use file UOS/Server/20/1050a/ks.cfg.
16. For UnionTech OS Server 20 1050e unattend auto-install, please use file UOS/Server/20/1050e/ks.cfg.
17. For Fedora Server 36 or later unattend auto-install, please use file Fedora/36/Server/ks.cfg.
18. For FreeBSD 13 or later unattend auto-install, please use file FreeBSD/installerconfig.

# Notes
## For Windows
Expand Down
14 changes: 14 additions & 0 deletions common/test_rescue.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,20 @@
download_file_fail_ignore: true
when: vm_dir_name is defined and vm_dir_name

- name: "Download serial output file"
include_tasks: 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
- guest_id is match('freebsd')

- name: "Take a snapshot at VM current state"
include_tasks: vm_take_snapshot.yml
vars:
Expand Down
8 changes: 6 additions & 2 deletions linux/deploy_vm/create_unattend_install_iso.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
- unattend_install_conf is not match('Photon')
- unattend_install_conf is not match('Debian')
- unattend_install_conf is not match('Ubuntu/Desktop/')
- unattend_install_conf is not match('FreeBSD')

- name: "Build unattend install config file into OS ISO image"
include_tasks: rebuild_unattend_install_iso.yml
Expand All @@ -72,7 +73,8 @@
when: >
unattend_install_conf is match('Photon') or
unattend_install_conf is match('Debian') or
unattend_install_conf is match('Ubuntu/Desktop/')
unattend_install_conf is match('Ubuntu/Desktop/') or
unattend_install_conf is match('FreeBSD')
when: unattend_install_conf is not match('Ubuntu/Server/')

# unattend_install_conf is for Ubuntu Server
Expand Down Expand Up @@ -136,6 +138,7 @@
- unattend_install_conf is not match('Photon')
- unattend_install_conf is not match('Debian')
- unattend_install_conf is not match('Ubuntu/Desktop')
- unattend_install_conf is not match('FreeBSD')

- name: "Replace original install ISO file with unattend install ISO file"
ansible.builtin.set_fact:
Expand All @@ -144,7 +147,8 @@
when: >
unattend_install_conf is match('Photon') or
unattend_install_conf is match('Debian') or
unattend_install_conf is match('Ubuntu/Desktop')
unattend_install_conf is match('Ubuntu/Desktop') or
unattend_install_conf is match('FreeBSD')
- name: "Copy generated unattend install config file to log folder"
ansible.builtin.copy:
Expand Down
5 changes: 5 additions & 0 deletions linux/deploy_vm/deploy_vm_from_iso.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@
ansible.builtin.set_fact:
unattend_install_conf: "Debian/10/preseed.cfg"
when: "'debian10' in guest_id or 'debian11' in guest_id"

- 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

- ansible.builtin.debug:
Expand Down
6 changes: 6 additions & 0 deletions linux/deploy_vm/eject_del_unattend_install_iso.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@
- 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"

# 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"
Expand Down
81 changes: 68 additions & 13 deletions linux/deploy_vm/rebuild_unattend_install_iso.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,30 +30,72 @@

- name: "Rebuild ISO for Ubuntu desktop"
block:
- name: Extract specific files inside ISO
- 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
- 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
- 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"
debug:
- name: "Print the content of modified file grub.cfg"
ansible.builtin.debug:
msg: "{{ lookup('file', src_iso_file_dir + '/grub.cfg') }}"

- name: Customize the ISO
- 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 }}"
Expand All @@ -62,11 +104,15 @@
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')

- name: "Rebuild ISO for Photon"
block:
- name: Extract specific files inside ISO
- name: "Extract specific files inside ISO"
community.general.iso_extract:
image: "{{ src_iso_file_path }}"
dest: "{{ src_iso_file_dir }}"
Expand All @@ -90,7 +136,7 @@
- "menu.cfg"
- "grub.cfg"

- name: Customize the ISO
- name: "Customize the ISO"
community.general.iso_customize:
src_iso: "{{ src_iso_file_path }}"
dest_iso: "{{ rebuilt_unattend_iso_path }}"
Expand All @@ -107,7 +153,7 @@

- name: "Rebuild ISO for Debian"
block:
- name: Extract specific files inside ISO
- name: "Extract specific files inside ISO"
community.general.iso_extract:
image: "{{ src_iso_file_path }}"
dest: "{{ src_iso_file_dir }}"
Expand Down Expand Up @@ -178,7 +224,7 @@
- name: "Print command output for updating initrd"
ansible.builtin.debug: var=update_initrd_output

- name: Customize the ISO
- name: "Customize the ISO"
community.general.iso_customize:
src_iso: "{{ src_iso_file_path }}"
dest_iso: "{{ rebuilt_unattend_iso_path }}"
Expand Down Expand Up @@ -228,7 +274,7 @@
ansible.builtin.set_fact:
ubuntu_bios_cfg_exist: false

- name: Extract isolinux/txt.cfg inside ISO if exists
- name: "Extract isolinux/txt.cfg inside ISO if exists"
community.general.iso_extract:
image: "{{ src_iso_file_path }}"
dest: "{{ src_iso_file_dir }}"
Expand Down Expand Up @@ -259,7 +305,7 @@
args:
chdir: "{{ unattend_iso_cache }}"

- name: Customize the ISO
- name: "Customize the ISO"
community.general.iso_customize:
src_iso: "{{ src_iso_file_path }}"
dest_iso: "{{ rebuilt_unattend_iso_path }}"
Expand All @@ -272,7 +318,7 @@
dest_file: "isolinux/txt.cfg"
when: ubuntu_bios_cfg_exist

- name: Customize the ISO without txt.cfg
- name: "Customize the ISO without txt.cfg"
community.general.iso_customize:
src_iso: "{{ src_iso_file_path }}"
dest_iso: "{{ rebuilt_unattend_iso_path }}"
Expand All @@ -283,3 +329,12 @@
dest_file: "md5sum.txt"
when: not ubuntu_bios_cfg_exist
when: unattend_install_conf is match('Ubuntu/Server')

- name: "Rebuild ISO for FreeBSD"
community.general.iso_customize:
src_iso: "{{ src_iso_file_path }}"
dest_iso: "{{ rebuilt_unattend_iso_path }}"
add_files:
- src_file: "{{ new_unattend_install_conf }}"
dest_file: "/etc/installerconfig"
when: unattend_install_conf is match('FreeBSD')
Loading

0 comments on commit 09a41bc

Please sign in to comment.