Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Support autoinstall for ubuntu 23.04 desktop #457

Merged
merged 33 commits into from
Apr 19, 2023
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
18969ed
support autointall for ubuntu 23.04 desktop
Apr 10, 2023
8755636
support autoinstall for ubuntu 23.04
Apr 10, 2023
e3d2f9c
support autointall for ubuntu desktop 23.04 or later
Apr 10, 2023
ce95134
modify autointall file
Apr 10, 2023
ea407a2
modify autoinstall config file
Apr 11, 2023
c417b7b
modify autoinstall config file
Apr 12, 2023
42b41d0
modify autoinstall file
Apr 12, 2023
fe0f5cf
modify autoinstall file
Apr 12, 2023
ebcbdaf
modify autoinstall file
Apr 12, 2023
d3d0931
modify autoinstall file
Apr 12, 2023
f343d40
modify autoinstall file
Apr 12, 2023
72eaba6
modify README file
Apr 12, 2023
76f745a
modify autoinstall file
Apr 13, 2023
1800c3d
change from codereview
Apr 13, 2023
98a33d7
change code from codereview
Apr 13, 2023
1d21b88
modify code as codereviww
Apr 13, 2023
be15430
wait extra 300s for rebooting ubuntu 23.04 or later
Apr 15, 2023
1c9d990
remove extra 300s for rebooting ubuntu 23.04 or later
Apr 15, 2023
69732fe
try workaroundto fix the issue: vm_primary_nic_mac is null for ubuntu…
Apr 17, 2023
7a450a3
try workaroundto fix the issue: vm_primary_nic_mac is nul
Apr 17, 2023
274d3a8
modify code from codereview
Apr 18, 2023
18b866d
add file vm_wait_primary_nic_mac.yml
Apr 18, 2023
5953396
remove unused file
Apr 18, 2023
2fc7350
change code as codereview
Apr 18, 2023
d972d2a
modify time to retry to get primary mac address
Apr 18, 2023
c2f32d2
change null or '' to bool
Apr 18, 2023
a4d0603
modify code from codereview
Apr 18, 2023
62c5c42
check the variable is null or not
Apr 18, 2023
f8999d8
modify the method to check null or not
Apr 19, 2023
00681a7
modify code as codereview
Apr 19, 2023
07064db
modify code as codereview
Apr 19, 2023
4c6d58b
modify code as codereview
Apr 19, 2023
0af05d8
modify code as review
Apr 19, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions autoinstall/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@
10. For Windows Server SAC unattend auto-install, please use files under Windows/win_server_sac.
11. For Photon OS 3.0 or later unattend auto-install, please use file Photon/ks.cfg.
12. For Ubuntu Server 20.04 or later unattend auto-install, please use file Ubuntu/Server/user-data.j2.
13. For Ubuntu Desktop 20.04 or later unattend auto-install, please use file Ubuntu/Desktop/ubuntu.seed
14. For Debian 10.1x or 11.x unattend auto-install, please use file Debian/10/preseed.cfg.
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.
13. For Ubuntu Desktop 20.04 ~ 22.10 unattend auto-install, please use file Ubuntu/Desktop/Ubiquity/ubuntu.seed.
14. For Ubuntu Destkop 23.04 or later unattend auto-install, please use file Ubuntu/Desktop/Subiquity/user-data.j2.
15. For Debian 10.1x or 11.x unattend auto-install, please use file Debian/10/preseed.cfg.
16. For UnionTech OS Server 20 1050a unattend auto-install, please use file UOS/Server/20/1050a/ks.cfg.
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.

# Notes
## For Windows
Expand Down
54 changes: 54 additions & 0 deletions autoinstall/Ubuntu/Desktop/Subiquity/user-data.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#cloud-config
autoinstall:
version: 1
early-commands:
- echo '{{ autoinstall_start_msg }}' >/dev/ttyS0
locale: en_US.UTF-8
keyboard:
layout: us
network:
version: 2
ethernets:
all-eth:
match:
name: "ens*"
dhcp4: yes
storage:
layout:
name: direct
grub:
reorder_uefi: False
timezone: US/Eastern
identity:
hostname: ubuntu
realname: ubuntu
username: {{ vm_username }}
password: {{ vm_password_hash }}
user-data:
users:
- name: root
lock_passwd: false
hashed_passwd: {{ vm_password_hash }}
ssh_authorized_keys:
- {{ ssh_public_key }}
{% if new_user is defined and new_user != 'root' %}
- name: {{ new_user }}
lock_passwd: false
hashed_passwd: {{ vm_password_hash }}
sudo: ALL=(ALL) NOPASSWD:ALL
ssh_authorized_keys:
- {{ ssh_public_key }}
{% endif %}
apt:
preserve_sources_list: false
geoip: true
late-commands:
- echo "# apt-get update" >> /dev/ttyS0
- curtin in-target --target=/target -- apt-get update -y >> /dev/ttyS0
- echo "# apt-get install build-essential openssh-server open-vm-tools open-vm-tools-desktop cloud-init rdma-core rdmacm-utils ibverbs-utils" >> /dev/ttyS0
- curtin in-target --target=/target -- apt-get install -y --force-yes build-essential openssh-server open-vm-tools open-vm-tools-desktop cloud-init rdma-core rdmacm-utils ibverbs-utils >> /dev/ttyS0
- rm -f /etc/cloud/cloud.cfg.d/*-installer.cfg 2>/dev/null
- 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'
54 changes: 54 additions & 0 deletions autoinstall/Ubuntu/Flutter/user-data.j2
ZouYuhua marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#cloud-config
autoinstall:
version: 1
early-commands:
- echo '{{ autoinstall_start_msg }}' >/dev/ttyS0
locale: en_US.UTF-8
keyboard:
layout: us
network:
version: 2
ethernets:
all-eth:
match:
name: "ens*"
ZouYuhua marked this conversation as resolved.
Show resolved Hide resolved
dhcp4: yes
storage:
layout:
name: direct
grub:
reorder_uefi: False
timezone: US/Eastern
identity:
hostname: ubuntu
realname: ubuntu
username: {{ vm_username }}
password: {{ vm_password_hash }}
user-data:
users:
- name: root
lock_passwd: false
hashed_passwd: {{ vm_password_hash }}
ssh_authorized_keys:
- {{ ssh_public_key }}
{% if new_user is defined and new_user != 'root' %}
- name: {{ new_user }}
lock_passwd: false
hashed_passwd: {{ vm_password_hash }}
sudo: ALL=(ALL) NOPASSWD:ALL
ssh_authorized_keys:
- {{ ssh_public_key }}
{% endif %}
apt:
preserve_sources_list: false
geoip: true
late-commands:
- echo "# apt-get update" >> /dev/ttyS0
- curtin in-target --target=/target -- apt-get update -y >> /dev/ttyS0
- echo "# apt-get install build-essential openssh-server open-vm-tools open-vm-tools-desktop cloud-init rdma-core rdmacm-utils ibverbs-utils" >> /dev/ttyS0
- curtin in-target --target=/target -- apt-get install -y --force-yes build-essential openssh-server open-vm-tools open-vm-tools-desktop cloud-init rdma-core rdmacm-utils ibverbs-utils >> /dev/ttyS0
ZouYuhua marked this conversation as resolved.
Show resolved Hide resolved
- rm -f /etc/cloud/cloud.cfg.d/*-installer.cfg 2>/dev/null
- 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'
3 changes: 3 additions & 0 deletions common/vm_get_vm_info.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
vm_hardware_version_num: "{{ vm_config.config.version.split('-')[-1] }}"
vm_primary_nic_mac: ""

- name: "Wait for mac address is available"
include_tasks: vm_wait_primary_nic_mac.yml

ZouYuhua marked this conversation as resolved.
Show resolved Hide resolved
- name: "Get VM's network adapter"
include_tasks: vm_get_network_facts.yml
ZouYuhua marked this conversation as resolved.
Show resolved Hide resolved

Expand Down
24 changes: 24 additions & 0 deletions common/vm_wait_primary_nic_mac.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Copyright 2021-2023 VMware, Inc.
ZouYuhua marked this conversation as resolved.
Show resolved Hide resolved
# SPDX-License-Identifier: BSD-2-Clause
---
# Sometime we need to wait for a while to get mac address after create VM
ZouYuhua marked this conversation as resolved.
Show resolved Hide resolved
- name: "Check the mac address is available or not"
ZouYuhua marked this conversation as resolved.
Show resolved Hide resolved
community.vmware.vmware_guest_network:
validate_certs: "{{ validate_certs | default(false) }}"
hostname: "{{ vsphere_host_name }}"
username: "{{ vsphere_host_user }}"
password: "{{ vsphere_host_user_password }}"
datacenter: "{{ vsphere_host_datacenter }}"
folder: "{{ vm_folder }}"
name: "{{ vm_name }}"
gather_network_info: true
register: gather_network_facts
until:
- gather_network_facts.network_data is defined
- gather_network_facts.network_data['0'] is defined
- gather_network_facts.network_data['0'].mac_addr is defined
- gather_network_facts.network_data['0'].mac_addr != ""
ZouYuhua marked this conversation as resolved.
Show resolved Hide resolved
retries: ((300 | int) / 5 ) | int
delay: 5
ignore_errors: true
changed_when: false
ZouYuhua marked this conversation as resolved.
Show resolved Hide resolved
2 changes: 1 addition & 1 deletion linux/deploy_vm/collect_vm_logs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
- 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
(unattend_install_conf is match('Ubuntu/Server/') or unattend_install_conf is match('Ubuntu/Desktop/Subiquity'))) or
(ova_guest_os_type is defined and
ova_guest_os_type in ['photon', 'ubuntu', 'amazon']))
when:
Expand Down
20 changes: 12 additions & 8 deletions linux/deploy_vm/create_unattend_install_iso.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
msg:
- "The unattend install config file is {{ unattend_install_template }}"

# unattend_install_conf is not for Ubuntu Server
# unattend_install_conf is not for Ubuntu Server, Ubuntu Desktop 23.04 and later
- block:
- name: "Create temp folder for generating unattend install ISO file"
include_tasks: ../../common/create_temp_file_dir.yml
Expand Down Expand Up @@ -63,7 +63,7 @@
when:
- 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('Ubuntu/Desktop/Ubiquity')
- unattend_install_conf is not match('FreeBSD')

- name: "Build unattend install config file into OS ISO image"
Expand All @@ -73,11 +73,13 @@
when: >
unattend_install_conf is match('Photon') or
unattend_install_conf is match('Debian') or
unattend_install_conf is match('Ubuntu/Desktop/') or
unattend_install_conf is match('Ubuntu/Desktop/Ubiquity') or
unattend_install_conf is match('FreeBSD')
when: unattend_install_conf is not match('Ubuntu/Server/')
when:
- unattend_install_conf is not match('Ubuntu/Server/')
- unattend_install_conf is not match('Ubuntu/Desktop/Subiquity')

# unattend_install_conf is for Ubuntu Server
# unattend_install_conf is for Ubuntu Server / Ubuntu desktop 23.04 or later
- block:
- name: "Set fact for autoinstall start message to be printed to VM serial port"
ansible.builtin.set_fact:
Expand Down Expand Up @@ -112,7 +114,9 @@
ansible.builtin.set_fact:
os_installation_iso_list: ["[{{ datastore }}] {{ new_os_installation_iso }}"]
os_install_iso_list_len: 1
when: unattend_install_conf is match('Ubuntu/Server/')
when: >
unattend_install_conf is match('Ubuntu/Server/') or
unattend_install_conf is match('Ubuntu/Desktop/Subiquity')

- name: "Set fact of unattended install ISO path on datastore {{ datastore }}"
ansible.builtin.set_fact:
Expand All @@ -137,7 +141,7 @@
when:
- 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('Ubuntu/Desktop/Ubiquity')
- unattend_install_conf is not match('FreeBSD')

- name: "Replace original install ISO file with unattend install ISO file"
Expand All @@ -147,7 +151,7 @@
when: >
unattend_install_conf is match('Photon') or
unattend_install_conf is match('Debian') or
unattend_install_conf is match('Ubuntu/Desktop') or
unattend_install_conf is match('Ubuntu/Desktop/Ubiquity') or
unattend_install_conf is match('FreeBSD')

- name: "Copy generated unattend install config file to log folder"
Expand Down
4 changes: 2 additions & 2 deletions linux/deploy_vm/deploy_vm_from_iso.yml
Original file line number Diff line number Diff line change
Expand Up @@ -163,12 +163,12 @@
# 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"
- 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')
- unattend_install_conf is match('Ubuntu/Desktop/Ubiquity')

# Wait autoinstall complete message appear in serial port output file
- include_tasks: ../../common/vm_wait_log_msg.yml
Expand Down
2 changes: 1 addition & 1 deletion linux/deploy_vm/eject_del_unattend_install_iso.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,6 @@
file_in_datastore_ops: "absent"
file_in_datastore_ignore_failed: true
when:
- unattend_install_conf is match('Ubuntu/Server')
- unattend_install_conf is match('Ubuntu/Server') or unattend_install_conf is match('Ubuntu/Desktop/Subiquity')
- new_os_installation_iso is defined
- new_os_installation_iso
9 changes: 5 additions & 4 deletions linux/deploy_vm/rebuild_unattend_install_iso.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
ansible.builtin.set_fact:
unattend_install_file_name: "{{ new_unattend_install_conf | basename }}"

- name: "Rebuild ISO for Ubuntu desktop"
- name: "Rebuild ISO for Ubuntu 20.04 ~ 22.10 desktop"
block:
- name: "Extract specific files inside ISO"
community.general.iso_extract:
Expand Down Expand Up @@ -108,7 +108,7 @@
- result_extract_file is defined
- result_extract_file.failed is defined
- result_extract_file.failed
when: unattend_install_conf is match('Ubuntu/Desktop')
when: unattend_install_conf is match('Ubuntu/Desktop/Ubiquity')

- name: "Rebuild ISO for Photon"
block:
Expand Down Expand Up @@ -256,6 +256,7 @@
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:
Expand Down Expand Up @@ -328,7 +329,7 @@
- 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')
when: unattend_install_conf is match('Ubuntu/Server') or unattend_install_conf is match('Ubuntu/Desktop/Subiquity')

- name: "Rebuild ISO for FreeBSD"
community.general.iso_customize:
Expand All @@ -337,4 +338,4 @@
add_files:
- src_file: "{{ new_unattend_install_conf }}"
dest_file: "/etc/installerconfig"
when: unattend_install_conf is match('FreeBSD')
when: unattend_install_conf is match('FreeBSD')
18 changes: 15 additions & 3 deletions linux/deploy_vm/ubuntu/prepare_ubuntu_iso_install.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,19 @@
unattend_install_conf: "Ubuntu/Server/user-data.j2"
when: ubuntu_install_method is defined and ubuntu_install_method == "cloud-init"
ZouYuhua marked this conversation as resolved.
Show resolved Hide resolved

- name: "Set fact of Ubuntu desktop unattend install file"
ansible.builtin.set_fact:
unattend_install_conf: "Ubuntu/Desktop/ubuntu.seed"
- name: "Set fact of Ubuntu desktop"
block:
- name: “Set autoinstall method for Ubuntu Desktop”
ansible.builtin.set_fact:
unattend_install_conf: "Ubuntu/Desktop/Ubiquity/ubuntu.seed"

- name: "Set fact of desktop unattend install file for Ubuntu 23.04 or later"
block:
- name: “Set autoinstall method for Ubuntu Desktop 23.04 or later”
ansible.builtin.set_fact:
ubuntu_install_method: "cloud-init"
- name: "Set fact of unattend install file for Ubuntu 23.04 or later"
ansible.builtin.set_fact:
unattend_install_conf: "Ubuntu/Desktop/Subiquity/user-data.j2"
when: ubuntu_version and ubuntu_version is version('23.04', '>=')
when: ubuntu_edition == 'desktop'