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 --- common/iso-generate.yml | 6 ++- common/usb-generate.yml | 9 ++-- roles/installer/debian/usb/tasks/main.yml | 4 +- .../autoinstall/templates/autoinstall.yml.j2 | 33 ++++++++------- 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 +++++++ 8 files changed, 113 insertions(+), 23 deletions(-) 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 diff --git a/common/iso-generate.yml b/common/iso-generate.yml index 504d91ae..78047e13 100644 --- a/common/iso-generate.yml +++ b/common/iso-generate.yml @@ -3,7 +3,9 @@ hosts: "{{ install_hostnames }}" connection: local gather_facts: no + vars: + installer_variant: debian roles: - - role: installer/debian/iso - installer_base_path: "{{ global_cache_dir }}/debian-installer" + - role: "installer/{{ installer_variant }}/iso" + installer_base_path: "{{ global_cache_dir }}/{{ installer_variant }}-installer" installer_keyrings_path: "{{ global_files_dir }}/common/keyrings" diff --git a/common/usb-generate.yml b/common/usb-generate.yml index 30b0f190..7031839c 100644 --- a/common/usb-generate.yml +++ b/common/usb-generate.yml @@ -3,12 +3,13 @@ hosts: "{{ install_hostnames }}" connection: local gather_facts: no + vars: + installer_variant: debian vars_prompt: - name: usb_install_path - prompt: Where is the USB installation medium mounted to? + prompt: "Path to the the USB installation mountpoint or device" private: no - roles: - - role: installer/debian/usb - installer_base_path: "{{ global_cache_dir }}/debian-installer" + - role: "installer/{{ installer_variant }}/usb" + installer_base_path: "{{ global_cache_dir }}/{{ installer_variant }}-installer" installer_keyrings_path: "{{ global_files_dir }}/common/keyrings" diff --git a/roles/installer/debian/usb/tasks/main.yml b/roles/installer/debian/usb/tasks/main.yml index 88da49c8..acc003a2 100644 --- a/roles/installer/debian/usb/tasks/main.yml +++ b/roles/installer/debian/usb/tasks/main.yml @@ -8,8 +8,8 @@ - name: fail if usb drive mountpoint does not exist run_once: true assert: - that: usb_install_mountpoint.stat.exists - msg: the path to the usb drive does not exist + that: usb_install_mountpoint.stat.exists and usb_install_mountpoint.stat.isdir + msg: the path to the usb drive does not exist or is not a directory - name: download installer run_once: true diff --git a/roles/installer/ubuntu/autoinstall/templates/autoinstall.yml.j2 b/roles/installer/ubuntu/autoinstall/templates/autoinstall.yml.j2 index 52eb0d44..e166a78f 100644 --- a/roles/installer/ubuntu/autoinstall/templates/autoinstall.yml.j2 +++ b/roles/installer/ubuntu/autoinstall/templates/autoinstall.yml.j2 @@ -65,34 +65,35 @@ autoinstall: number: 1 size: {{ ubuntu_autoinstall_efi_esp_size | human_to_bytes }} grub_device: true + - id: format-esp + type: format + volume: partition-esp + label: efi + fstype: fat32 + - id: mount-esp + type: mount + device: format-esp + path: /boot/efi {% else %} {% for raid_member in install_cooked.disks.raid.members %} - - id: raid-partition-esp{{ loop.index }} + - id: partition-esp{{ loop.index }} type: partition device: raid-disk{{ loop.index }} flag: boot number: 1 size: {{ ubuntu_autoinstall_efi_esp_size | human_to_bytes }} grub_device: true -{% endfor %} - - id: partition-esp - type: raid - raidlevel: {{ install_cooked.disks.raid.level }} - metadata: 0.90 - devices: -{% for raid_member in install_cooked.disks.raid.members %} - - raid-partition-esp{{ loop.index }} -{% endfor %} -{% endif %} - - id: format-esp + - id: format-esp{{ loop.index }} type: format - volume: partition-esp + volume: partition-esp{{ loop.index }} label: efi fstype: fat32 - - id: mount-esp + - id: mount-esp{{ loop.index }} type: mount - device: format-esp + device: format-esp{{ loop.index }} path: /boot/efi +{% endfor %} +{% endif %} {% else %} {% set part_offset = 0 %} @@ -107,6 +108,7 @@ autoinstall: {% endfor %} - id: partition-boot type: raid + name: md-boot raidlevel: {{ install_cooked.disks.raid.level }} devices: {% for raid_member in install_cooked.disks.raid.members %} @@ -159,6 +161,7 @@ autoinstall: {% endfor %} - id: partition-lvm type: raid + name: md-lvm raidlevel: {{ install_cooked.disks.raid.level }} devices: {% for raid_member in install_cooked.disks.raid.members %} 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