diff --git a/autoinstall/README.md b/autoinstall/README.md index 0aa3cef44..d140c1f3d 100644 --- a/autoinstall/README.md +++ b/autoinstall/README.md @@ -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 diff --git a/autoinstall/Ubuntu/Desktop/Subiquity/user-data.j2 b/autoinstall/Ubuntu/Desktop/Subiquity/user-data.j2 new file mode 100644 index 000000000..826b4d1b9 --- /dev/null +++ b/autoinstall/Ubuntu/Desktop/Subiquity/user-data.j2 @@ -0,0 +1,47 @@ +#cloud-config +autoinstall: + version: 1 + early-commands: + - echo '{{ autoinstall_start_msg }}' >/dev/ttyS0 + locale: en_US.UTF-8 + keyboard: + layout: us + 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' diff --git a/autoinstall/Ubuntu/Desktop/ubuntu.seed b/autoinstall/Ubuntu/Desktop/Ubiquity/ubuntu.seed similarity index 100% rename from autoinstall/Ubuntu/Desktop/ubuntu.seed rename to autoinstall/Ubuntu/Desktop/Ubiquity/ubuntu.seed diff --git a/common/README.md b/common/README.md index 1db6cedcd..1e3e7b803 100644 --- a/common/README.md +++ b/common/README.md @@ -51,6 +51,7 @@ * vm_configure_network_adapter.yml: Reconfig VM network adapter connection settings * vm_wait_network_connected.yml: Wait for network adapter to be connected * vm_get_network_facts.yml: Get VM network adapters info +* vm_wait_primary_nic_mac.yml: Wait for VM's primary network adapter having MAC address * vm_get_netadapter_number.yml: Get VM network adapters number with different types ### Tasks for VM disk settings diff --git a/common/vm_get_vm_info.yml b/common/vm_get_vm_info.yml index 25b2ebe5b..97f19c05c 100644 --- a/common/vm_get_vm_info.yml +++ b/common/vm_get_vm_info.yml @@ -22,18 +22,9 @@ vm_guest_os_version: "{{ vm_config.config.guestFullName }}" vm_hardware_version: "{{ vm_config.config.version }}" vm_hardware_version_num: "{{ vm_config.config.version.split('-')[-1] }}" - vm_primary_nic_mac: "" -- name: "Get VM's network adapter" - include_tasks: vm_get_network_facts.yml - -- name: "Set fact of VM's primary network adapter MAC address" - ansible.builtin.set_fact: - vm_primary_nic_mac: "{{ vm_network_adapters['0'].mac_addr }}" - when: - - vm_network_adapters is defined - - vm_network_adapters['0'] is defined - - vm_network_adapters['0'].mac_addr is defined +- name: "Wait for mac address is available" + include_tasks: vm_wait_primary_nic_mac.yml - name: "Display VM's information" ansible.builtin.debug: @@ -46,4 +37,3 @@ - "VM guest ID: {{ vm_guest_id }}" - "VM hardware version: {{ vm_hardware_version }}" - "VM hardware version number: {{ vm_hardware_version_num }}" - - "VM primary network adapter MAC address: {{ vm_primary_nic_mac }}" diff --git a/common/vm_wait_primary_nic_mac.yml b/common/vm_wait_primary_nic_mac.yml new file mode 100644 index 000000000..21e3c183c --- /dev/null +++ b/common/vm_wait_primary_nic_mac.yml @@ -0,0 +1,47 @@ +# Copyright 2023 VMware, Inc. +# SPDX-License-Identifier: BSD-2-Clause +--- +# Wait for VM's primary network adapter having MAC address +# +- name: "Initialize primary network adapter MAC address" + ansible.builtin.set_fact: + vm_primary_nic_mac: "" + +- name: "Wait for VM primary network adapter MAC address" + 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 + retries: 20 + delay: 3 + ignore_errors: true + changed_when: false + +- name: "Print the VM network info" + ansible.builtin.debug: var=gather_network_facts + when: enable_debug is defined and enable_debug + +- name: "Set fact of VM's primary network adapter MAC address" + ansible.builtin.set_fact: + vm_primary_nic_mac: "{{ gather_network_facts.network_data['0'].mac_addr }}" + when: + - 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 + +- name: "Display VM's primary network adapter MAC address" + ansible.builtin.debug: + msg: + - "VM primary network adapter MAC address: {{ vm_primary_nic_mac }}" \ No newline at end of file diff --git a/linux/deploy_vm/collect_vm_logs.yml b/linux/deploy_vm/collect_vm_logs.yml index e9db3d19b..af9775efb 100644 --- a/linux/deploy_vm/collect_vm_logs.yml +++ b/linux/deploy_vm/collect_vm_logs.yml @@ -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: diff --git a/linux/deploy_vm/create_unattend_install_iso.yml b/linux/deploy_vm/create_unattend_install_iso.yml index 8822dbeb6..80b3e6606 100644 --- a/linux/deploy_vm/create_unattend_install_iso.yml +++ b/linux/deploy_vm/create_unattend_install_iso.yml @@ -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 @@ -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" @@ -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: @@ -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: @@ -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" @@ -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" diff --git a/linux/deploy_vm/deploy_vm_from_iso.yml b/linux/deploy_vm/deploy_vm_from_iso.yml index 8ed638df4..1ebfae5d1 100644 --- a/linux/deploy_vm/deploy_vm_from_iso.yml +++ b/linux/deploy_vm/deploy_vm_from_iso.yml @@ -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 @@ -187,6 +187,10 @@ when: - unattend_install_conf is defined - unattend_install_conf is match('Photon') or unattend_install_conf is match('Ubuntu') + + - name: "Get VM's primary network adapter MAC address after poweron VM" + include_tasks: ../../common/vm_wait_primary_nic_mac.yml + when: vm_primary_nic_mac is undefined or not vm_primary_nic_mac # Get guest IP - include_tasks: ../../common/update_inventory.yml diff --git a/linux/deploy_vm/eject_del_unattend_install_iso.yml b/linux/deploy_vm/eject_del_unattend_install_iso.yml index ebafdb177..6612d3fea 100644 --- a/linux/deploy_vm/eject_del_unattend_install_iso.yml +++ b/linux/deploy_vm/eject_del_unattend_install_iso.yml @@ -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 diff --git a/linux/deploy_vm/rebuild_unattend_install_iso.yml b/linux/deploy_vm/rebuild_unattend_install_iso.yml index 47d1fe494..4ee6cbb35 100644 --- a/linux/deploy_vm/rebuild_unattend_install_iso.yml +++ b/linux/deploy_vm/rebuild_unattend_install_iso.yml @@ -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: @@ -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: @@ -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: @@ -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: @@ -337,4 +338,4 @@ add_files: - src_file: "{{ new_unattend_install_conf }}" dest_file: "/etc/installerconfig" - when: unattend_install_conf is match('FreeBSD') \ No newline at end of file + when: unattend_install_conf is match('FreeBSD') diff --git a/linux/deploy_vm/ubuntu/prepare_ubuntu_iso_install.yml b/linux/deploy_vm/ubuntu/prepare_ubuntu_iso_install.yml index 9cd178310..7a8ee3a99 100644 --- a/linux/deploy_vm/ubuntu/prepare_ubuntu_iso_install.yml +++ b/linux/deploy_vm/ubuntu/prepare_ubuntu_iso_install.yml @@ -14,21 +14,34 @@ {%- else -%}unknown {%- endif -%} -- name: "Set Ubuntu autoinstall method" - ansible.builtin.set_fact: - ubuntu_install_method: |- - {%- if ubuntu_version and ubuntu_version is version('20.04', '>=') -%}cloud-init - {%- elif ubuntu_version and ubuntu_version is version('20.04', '<') -%}simulation - {%- else -%}cloud-init - {%- endif -%} +- name: "Set fact of Ubuntu Server" + block: + - name: "Set Ubuntu autoinstall method" + ansible.builtin.set_fact: + ubuntu_install_method: |- + {%- if ubuntu_version and ubuntu_version is version('20.04', '<') -%}simulation + {%- else -%}cloud-init + {%- endif -%} + + - name: "Set fact of Ubuntu unattend install file" + ansible.builtin.set_fact: + unattend_install_conf: "Ubuntu/Server/user-data.j2" + when: ubuntu_install_method == "cloud-init" when: ubuntu_edition == 'server' -- name: "Set fact of Ubuntu unattend install file" - ansible.builtin.set_fact: - unattend_install_conf: "Ubuntu/Server/user-data.j2" - when: ubuntu_install_method is defined and ubuntu_install_method == "cloud-init" +- 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 Ubuntu desktop unattend install file" - ansible.builtin.set_fact: - unattend_install_conf: "Ubuntu/Desktop/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' diff --git a/windows/deploy_vm/deploy_vm_from_iso.yml b/windows/deploy_vm/deploy_vm_from_iso.yml index ed864f536..e3a554d53 100644 --- a/windows/deploy_vm/deploy_vm_from_iso.yml +++ b/windows/deploy_vm/deploy_vm_from_iso.yml @@ -107,6 +107,10 @@ - name: "Wait for VM network adapter is connected" include_tasks: ../../common/vm_wait_network_connected.yml +- name: "Get VM's primary network adapter MAC address after poweron VM" + include_tasks: ../../common/vm_wait_primary_nic_mac.yml + when: vm_primary_nic_mac is undefined or not vm_primary_nic_mac + - name: "Get VM IP address" include_tasks: ../../common/vm_get_ip.yml vars: diff --git a/windows/deploy_vm/deploy_vm_from_ova.yml b/windows/deploy_vm/deploy_vm_from_ova.yml index aea856829..a19f07ee8 100644 --- a/windows/deploy_vm/deploy_vm_from_ova.yml +++ b/windows/deploy_vm/deploy_vm_from_ova.yml @@ -41,15 +41,15 @@ ansible.builtin.set_fact: vm_exists: true -- name: "Get VM info" - include_tasks: ../../common/vm_get_vm_info.yml - # Power on VM and wait for guest fullname reported by VMware tools - name: "Power on VM" include_tasks: ../../common/vm_set_power_state.yml vars: vm_power_state_set: "powered-on" +- name: "Get VM info" + include_tasks: ../../common/vm_get_vm_info.yml + # Get OVA deployed VM info - name: "Collect hardware configs of the VM deployed from OVF" include_tasks: ../../common/collect_ovf_vm_config.yml