From f8a7983a5fa4f6f1e583838ec0de82af08bbe340 Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Wed, 30 Jun 2021 20:07:53 +0200 Subject: fix some issues with ubuntu autoinstall and add preliminary ubuntu/usb installer role --- roles/installer/ubuntu/usb/defaults/main.yml | 3 ++ roles/installer/ubuntu/usb/tasks/main.yml | 48 ++++++++++++++++++++++ roles/installer/ubuntu/usb/templates/grub.cfg.j2 | 18 ++++++++ .../installer/ubuntu/usb/templates/isolinux.cfg.j2 | 15 +++++++ 4 files changed, 84 insertions(+) create mode 100644 roles/installer/ubuntu/usb/defaults/main.yml create mode 100644 roles/installer/ubuntu/usb/tasks/main.yml create mode 100644 roles/installer/ubuntu/usb/templates/grub.cfg.j2 create mode 100644 roles/installer/ubuntu/usb/templates/isolinux.cfg.j2 (limited to 'roles/installer/ubuntu/usb') diff --git a/roles/installer/ubuntu/usb/defaults/main.yml b/roles/installer/ubuntu/usb/defaults/main.yml new file mode 100644 index 00000000..8afdb9f0 --- /dev/null +++ b/roles/installer/ubuntu/usb/defaults/main.yml @@ -0,0 +1,3 @@ +--- +### 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 new file mode 100644 index 00000000..26df154d --- /dev/null +++ b/roles/installer/ubuntu/usb/tasks/main.yml @@ -0,0 +1,48 @@ +--- +- name: check if usb drive device exists + run_once: true + stat: + path: "{{ usb_install_path }}" + register: usb_install_device + +- name: fail if usb drive path is not a device + run_once: true + assert: + 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 + +- block: + - name: create temporary workdir + tempfile: + prefix: "usb-install.{{ inventory_hostname }}." + state: directory + register: tmpdir + + - name: generate autoinstall files + vars: + ubuntu_autoinstall_tmpdir: "{{ tmpdir.path }}" + import_role: + name: installer/ubuntu/autoinstall + + - name: generate isolinux configuration for BIOS boot + template: + src: isolinux.cfg.j2 + dest: "{{ tmpdir.path }}/isolinux.cfg" + + - name: generate grub configuration for UEFI boot + template: + src: grub.cfg.j2 + dest: "{{ tmpdir.path }}/grub.cfg" + + - name: update iso9660 filesystem on installer usb drive + 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: + chdir: "{{ tmpdir.path }}" + + always: + - name: cleanup temporary workdir + when: tmpdir.path is defined + file: + path: "{{ tmpdir.path }}" + state: absent diff --git a/roles/installer/ubuntu/usb/templates/grub.cfg.j2 b/roles/installer/ubuntu/usb/templates/grub.cfg.j2 new file mode 100644 index 00000000..6ba4e6be --- /dev/null +++ b/roles/installer/ubuntu/usb/templates/grub.cfg.j2 @@ -0,0 +1,18 @@ +if loadfont $prefix/font.pf2 ; then + set gfxmode=auto + insmod efi_gop + insmod efi_uga + insmod gfxterm + terminal_output gfxterm +fi + +set menu_color_normal=white/black +set menu_color_highlight=black/light-gray +set timeout=10 +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(' ') }} + initrd /casper/initrd +} diff --git a/roles/installer/ubuntu/usb/templates/isolinux.cfg.j2 b/roles/installer/ubuntu/usb/templates/isolinux.cfg.j2 new file mode 100644 index 00000000..68269dfc --- /dev/null +++ b/roles/installer/ubuntu/usb/templates/isolinux.cfg.j2 @@ -0,0 +1,15 @@ +DEFAULT {{ inventory_hostname }} +TIMEOUT 100 +PROMPT 1 +SAY ***************************************** +SAY ** +SAY ** Distro: {{ install_distro }} +SAY ** Codename: {{ install_codename }} +SAY ** +SAY ** will be booting automated installer for {{ inventory_hostname }} in 10s ... +SAY ** + +LABEL {{ inventory_hostname }} + KERNEL /casper/vmlinuz + INITRD /casper/initrd + APPEND quiet autoinstall ds=nocloud;s=/cdrom/autoinstall/ {{ (install_cooked.kernel_cmdline | default([])) | join(' ') }} -- cgit v1.2.3