From 8ef2f52313f5affce1614c9eee27d6466fc6f46d Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Thu, 1 Jul 2021 01:21:02 +0200 Subject: ubuntu usb installer can now install multiple hosts from same drive --- roles/installer/ubuntu/autoinstall/tasks/main.yml | 7 ++++--- roles/installer/ubuntu/iso/templates/grub.cfg.j2 | 2 +- .../installer/ubuntu/iso/templates/isolinux.cfg.j2 | 2 +- roles/installer/ubuntu/usb/defaults/main.yml | 3 +++ roles/installer/ubuntu/usb/tasks/main.yml | 23 ++++++++++++++++++++++ roles/installer/ubuntu/usb/templates/grub.cfg.j2 | 8 ++++++-- .../installer/ubuntu/usb/templates/isolinux.cfg.j2 | 14 +++++++++++-- 7 files changed, 50 insertions(+), 9 deletions(-) diff --git a/roles/installer/ubuntu/autoinstall/tasks/main.yml b/roles/installer/ubuntu/autoinstall/tasks/main.yml index 4a3034d0..a7ea67ba 100644 --- a/roles/installer/ubuntu/autoinstall/tasks/main.yml +++ b/roles/installer/ubuntu/autoinstall/tasks/main.yml @@ -1,15 +1,16 @@ --- - name: create autoinstall sub-directory file: - path: "{{ ubuntu_autoinstall_tmpdir }}/autoinstall" + path: "{{ ubuntu_autoinstall_tmpdir }}/autoinstall/{{ inventory_hostname }}" state: directory - name: create empty meta-data file copy: content: "" - dest: "{{ ubuntu_autoinstall_tmpdir }}/autoinstall/meta-data" + dest: "{{ ubuntu_autoinstall_tmpdir }}/autoinstall/{{ inventory_hostname }}/meta-data" - name: copy early-command script + run_once: yes copy: src: early-command.py dest: "{{ ubuntu_autoinstall_tmpdir }}/autoinstall/early-command.py" @@ -17,4 +18,4 @@ - name: generate autoinstall.yml as user-data template: src: autoinstall.yml.j2 - dest: "{{ ubuntu_autoinstall_tmpdir }}/autoinstall/user-data" + dest: "{{ ubuntu_autoinstall_tmpdir }}/autoinstall/{{ inventory_hostname }}/user-data" diff --git a/roles/installer/ubuntu/iso/templates/grub.cfg.j2 b/roles/installer/ubuntu/iso/templates/grub.cfg.j2 index 6ba4e6be..0b598c2e 100644 --- a/roles/installer/ubuntu/iso/templates/grub.cfg.j2 +++ b/roles/installer/ubuntu/iso/templates/grub.cfg.j2 @@ -13,6 +13,6 @@ set default=0 menuentry "automated installer for {{ inventory_hostname }}" { set gfxpayload=keep - linux /casper/vmlinuz quiet autoinstall "ds=nocloud;s=/cdrom/autoinstall/" {{ (install_cooked.kernel_cmdline | default([])) | join(' ') }} + linux /casper/vmlinuz quiet autoinstall "ds=nocloud;s=/cdrom/autoinstall/{{ inventory_hostname }}/" {{ (install_cooked.kernel_cmdline | default([])) | join(' ') }} initrd /casper/initrd } diff --git a/roles/installer/ubuntu/iso/templates/isolinux.cfg.j2 b/roles/installer/ubuntu/iso/templates/isolinux.cfg.j2 index 68269dfc..ac94ac00 100644 --- a/roles/installer/ubuntu/iso/templates/isolinux.cfg.j2 +++ b/roles/installer/ubuntu/iso/templates/isolinux.cfg.j2 @@ -12,4 +12,4 @@ SAY ** LABEL {{ inventory_hostname }} KERNEL /casper/vmlinuz INITRD /casper/initrd - APPEND quiet autoinstall ds=nocloud;s=/cdrom/autoinstall/ {{ (install_cooked.kernel_cmdline | default([])) | join(' ') }} + APPEND quiet autoinstall ds=nocloud;s=/cdrom/autoinstall/{{ inventory_hostname }}/ {{ (install_cooked.kernel_cmdline | default([])) | join(' ') }} diff --git a/roles/installer/ubuntu/usb/defaults/main.yml b/roles/installer/ubuntu/usb/defaults/main.yml index 8afdb9f0..5467946d 100644 --- a/roles/installer/ubuntu/usb/defaults/main.yml +++ b/roles/installer/ubuntu/usb/defaults/main.yml @@ -1,3 +1,6 @@ --- +ubuntu_installer_usb_variant: live-server +# ubuntu_installer_usb_variant: desktop + ### path to the unmounted usb drive (/dev/...) # installer_ubuntu_usb_devicepath diff --git a/roles/installer/ubuntu/usb/tasks/main.yml b/roles/installer/ubuntu/usb/tasks/main.yml index 26df154d..c29fe2f8 100644 --- a/roles/installer/ubuntu/usb/tasks/main.yml +++ b/roles/installer/ubuntu/usb/tasks/main.yml @@ -11,8 +11,27 @@ that: usb_install_device.stat.exists and usb_install_device.stat.isblk msg: the path to the usb drive does not exist or is not a block device +- name: download installer + run_once: true + vars: + ubuntu_installer_codename: "{{ install_codename }}" + ubuntu_installer_arch: "{{ install_cooked.arch | default('amd64') }}" + ubuntu_installer_variant: "{{ ubuntu_installer_usb_variant }}" + import_role: + role: installer/ubuntu/fetch + +- name: write ISO image to usb stick + pause: + prompt: | + Please write the image to the USB drive using something like this: + + $ sudo ddrescue {{ ubuntu_installer_target_dir }}/{{ ubuntu_installer_filename }} {{ usb_install_path }} -D --force + + This will NOT be done automatically. + - block: - name: create temporary workdir + run_once: true tempfile: prefix: "usb-install.{{ inventory_hostname }}." state: directory @@ -25,16 +44,19 @@ name: installer/ubuntu/autoinstall - name: generate isolinux configuration for BIOS boot + run_once: true template: src: isolinux.cfg.j2 dest: "{{ tmpdir.path }}/isolinux.cfg" - name: generate grub configuration for UEFI boot + run_once: true template: src: grub.cfg.j2 dest: "{{ tmpdir.path }}/grub.cfg" - name: update iso9660 filesystem on installer usb drive + run_once: true become: yes command: xorriso -dev "stdio:{{ usb_install_path }}" -pathspecs on -boot_image any replay -update isolinux.cfg /isolinux/isolinux.cfg -update grub.cfg /boot/grub/grub.cfg -find / -disk_name autoinstall -type d -exec rm_r -- -add /autoinstall=autoinstall args: @@ -42,6 +64,7 @@ always: - name: cleanup temporary workdir + run_once: true when: tmpdir.path is defined file: path: "{{ tmpdir.path }}" diff --git a/roles/installer/ubuntu/usb/templates/grub.cfg.j2 b/roles/installer/ubuntu/usb/templates/grub.cfg.j2 index a9a1761c..1f97113a 100644 --- a/roles/installer/ubuntu/usb/templates/grub.cfg.j2 +++ b/roles/installer/ubuntu/usb/templates/grub.cfg.j2 @@ -8,11 +8,15 @@ fi set menu_color_normal=white/black set menu_color_highlight=black/light-gray +{% if (ansible_play_hosts_all | length) == 1 %} set timeout=10 set default=0 +{% endif %} +{% for host in ansible_play_hosts_all %} -menuentry "automated installer for {{ inventory_hostname }}" { +menuentry "automated installer for {{ host }}" { set gfxpayload=keep - linux /casper/vmlinuz quiet nopersistent autoinstall "ds=nocloud;s=/cdrom/autoinstall/" {{ (install_cooked.kernel_cmdline | default([])) | join(' ') }} + linux /casper/vmlinuz quiet nopersistent autoinstall "ds=nocloud;s=/cdrom/autoinstall/{{ host }}/" {{ (hostvars[host].install_cooked.kernel_cmdline | default([])) | join(' ') }} initrd /casper/initrd } +{% endfor %} diff --git a/roles/installer/ubuntu/usb/templates/isolinux.cfg.j2 b/roles/installer/ubuntu/usb/templates/isolinux.cfg.j2 index 4c84dd45..8360c057 100644 --- a/roles/installer/ubuntu/usb/templates/isolinux.cfg.j2 +++ b/roles/installer/ubuntu/usb/templates/isolinux.cfg.j2 @@ -1,3 +1,4 @@ +{% if (ansible_play_hosts_all | length) == 1 %} DEFAULT {{ inventory_hostname }} TIMEOUT 100 PROMPT 1 @@ -8,8 +9,17 @@ SAY ** Codename: {{ install_codename }} SAY ** SAY ** will be booting automated installer for {{ inventory_hostname }} in 10s ... SAY ** +{% else %} +DEFAULT menu.c32 +TIMEOUT 0 +PROMPT 0 +MENU TITLE {{ install_distro }} / {{ install_codename }} +{% endif %} +{% for host in ansible_play_hosts_all %} -LABEL {{ inventory_hostname }} +LABEL {{ host }} + MENU LABEL automatic installer for {{ host }} KERNEL /casper/vmlinuz INITRD /casper/initrd - APPEND quiet nopersistent autoinstall ds=nocloud;s=/cdrom/autoinstall/ {{ (install_cooked.kernel_cmdline | default([])) | join(' ') }} + APPEND quiet nopersistent autoinstall ds=nocloud;s=/cdrom/autoinstall/{{ host }}/ {{ (hostvars[host].install_cooked.kernel_cmdline | default([])) | join(' ') }} +{% endfor %} -- cgit v1.2.3