diff options
Diffstat (limited to 'roles/installer/ubuntu/usb')
-rw-r--r-- | roles/installer/ubuntu/usb/defaults/main.yml | 6 | ||||
-rw-r--r-- | roles/installer/ubuntu/usb/tasks/main.yml | 71 | ||||
-rw-r--r-- | roles/installer/ubuntu/usb/templates/grub.cfg.j2 | 22 | ||||
-rw-r--r-- | roles/installer/ubuntu/usb/templates/isolinux.cfg.j2 | 25 |
4 files changed, 124 insertions, 0 deletions
diff --git a/roles/installer/ubuntu/usb/defaults/main.yml b/roles/installer/ubuntu/usb/defaults/main.yml new file mode 100644 index 00000000..5467946d --- /dev/null +++ b/roles/installer/ubuntu/usb/defaults/main.yml @@ -0,0 +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 new file mode 100644 index 00000000..c7eb9e41 --- /dev/null +++ b/roles/installer/ubuntu/usb/tasks/main.yml @@ -0,0 +1,71 @@ +--- +- 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 + +- 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) | path_join | realpath }} {{ 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 + 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 + 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: + chdir: "{{ tmpdir.path }}" + + always: + - name: cleanup temporary workdir + run_once: true + 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..adeb5672 --- /dev/null +++ b/roles/installer/ubuntu/usb/templates/grub.cfg.j2 @@ -0,0 +1,22 @@ +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 +{% 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 {{ host }}" { + set gfxpayload=keep + 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 new file mode 100644 index 00000000..03d581d4 --- /dev/null +++ b/roles/installer/ubuntu/usb/templates/isolinux.cfg.j2 @@ -0,0 +1,25 @@ +{% if (ansible_play_hosts_all | length) == 1 %} +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 ** +{% else %} +DEFAULT menu.c32 +TIMEOUT 0 +PROMPT 0 +MENU TITLE {{ install_distro }} / {{ install_codename }} +{% endif %} +{% for host in ansible_play_hosts_all %} + +LABEL {{ host }} + MENU LABEL automated installer for {{ host }} + KERNEL /casper/vmlinuz + INITRD /casper/initrd + APPEND quiet nopersistent autoinstall ds=nocloud;s=/cdrom/autoinstall/{{ host }}/ {{ (hostvars[host].install_cooked.kernel_cmdline | default([])) | join(' ') }} +{% endfor %} |