From 7b1e504b8b17b0e1e3caf1de3f1a3ac5cc0f3f17 Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Sun, 5 Jul 2020 23:28:12 +0200 Subject: renovate usb-install --- common/usb-install.yml | 112 +++++++++++++----------------- roles/installer/debian/usb/tasks/main.yml | 52 +++++++++++++- 2 files changed, 97 insertions(+), 67 deletions(-) diff --git a/common/usb-install.yml b/common/usb-install.yml index 56508af8..27633c15 100644 --- a/common/usb-install.yml +++ b/common/usb-install.yml @@ -5,84 +5,66 @@ gather_facts: no vars_prompt: - - name: usbdrive_path + - name: usb_install_path prompt: Where is the USB installation medium mounted to? - default: "" private: no - pre_tasks: - - set_fact: - artifacts_dir: "{{ global_artifacts_dir }}/{{ install_hostname }}" - installer_path: "{{ global_cache_dir }}/debian-installer" - - - file: - state: directory - name: "{{ artifacts_dir }}" - roles: - role: installer/debian/usb + installer_path: "{{ global_cache_dir }}/debian-installer" post_tasks: - - stat: - path: "{{ usbdrive_path }}" - register: pathcheck + - name: Make the USB disk bootable + pause: + seconds: 0 + prompt: | + You should make sure the USB disk is bootable and + has syslinux installed. + + $ sudo apt install mbr syslinux + $ sudo install-mbr /dev/CHANGEME + $ sudo syslinux -i /dev/CHANGEME1 + $ sudo fdisk /dev/CHANGEME + [Here, make sure partition 1 is marked bootable.] - - when: pathcheck.stat.exists - block: - - name: Copy generated files to the USB drive - loop: - - "{{ artifacts_dir }}/initrd.preseed.gz" - - "{{ global_cache_dir }}/debian-installer/{{ install_distro }}-{{ install_codename }}/{{ install.arch | default('amd64') }}/linux" - loop_control: - label: "{{ item | basename }}" - copy: - src: "{{ item }}" - dest: "{{ usbdrive_path }}/" + for UEFI these steps need to be done - - name: Generate syslinux configuration for BIOS boot - copy: - dest: "{{ usbdrive_path }}/syslinux.cfg" - content: | - DEFAULT linux - SAY SYSLINUX booting an automated installer for {{ install_hostname }}... - LABEL linux - KERNEL linux - INITRD initrd.preseed.gz - APPEND install {{ (install.kernel_cmdline | default([])) | join(' ') }} + $ sudo apt install syslinux-efi + $ cp /usr/lib/syslinux/modules/efi64/* {{ usb_install_path }}/EFI/boot/ + $ cp /usr/lib/SYSLINUX.EFI/efi64/syslinux.efi {{ usb_install_path }}/EFI/boot/bootx64.efi - - name: create EFI boot directory - file: - path: "{{ usbdrive_path }}/EFI/boot" - state: directory + This will NOT be done automatically. - - name: Generate syslinux configuration for UEFI boot - copy: - dest: "{{ usbdrive_path }}/EFI/boot/syslinux.cfg" - content: | - DEFAULT linux - SAY SYSLINUX booting an automated installer for {{ install_hostname }}... - LABEL linux - KERNEL ../../linux - INITRD ../../initrd.preseed.gz - APPEND install {{ (install.kernel_cmdline | default([])) | join(' ') }} +- name: wait for new machine to start up + hosts: "{{ install_hostname }}" + gather_facts: no + tasks: + - pause: + prompt: | + Please plug the stick into the machine and boot from it. + When the installation is done press enter to continue or Ctrl-C + 'A' to abort. - - name: Make the USB disk bootable - pause: - seconds: 0 - prompt: | - You should make sure the USB disk is bootable and - has syslinux installed. + ## TODO: find a better way to fetch host key of new VMs + - name: disable ssh StrictHostKeyChecking for the next step + set_fact: + ansible_ssh_extra_args: -o StrictHostKeyChecking=no - $ sudo apt install mbr syslinux - $ sudo install-mbr /dev/CHANGEME - $ sudo syslinux -i /dev/CHANGEME1 - $ sudo fdisk /dev/CHANGEME - [Here, make sure partition 1 is marked bootable.] + - name: clear all gathered facts + meta: clear_facts - for UEFI these steps need to be done + - name: wait for vm to start up + wait_for_connection: + delay: 5 + timeout: 120 - $ sudo apt install syslinux-efi - $ cp /usr/lib/syslinux/modules/efi64/* {{ usbdrive_path }}/EFI/boot/ - $ cp /usr/lib/SYSLINUX.EFI/efi64/syslinux.efi {{ usbdrive_path }}/EFI/boot/bootx64.efi + - name: reenable StrictHostKeyChecking + set_fact: + ansible_ssh_extra_args: "" - This will NOT be done automatically. +- name: run host playbook + vars: + params: + files: + - "../{{ install_environment }}/{{ install_hostname }}.yml" + - "../{{ install_environment }}/{{ install_playbook | default('common') }}.yml" + import_playbook: "{{ q('first_found', params) | first }}" diff --git a/roles/installer/debian/usb/tasks/main.yml b/roles/installer/debian/usb/tasks/main.yml index 60c2dfd5..faf240ad 100644 --- a/roles/installer/debian/usb/tasks/main.yml +++ b/roles/installer/debian/usb/tasks/main.yml @@ -1,4 +1,14 @@ --- +- name: check if usb drive mountpoint exists + stat: + path: "{{ usb_install_path }}" + register: usb_install_mountpoint + +- name: fail if usb drive mountpoint does not exist + assert: + that: usb_install_mountpoint.stat.exists + msg: the path to the usb drive does not exist + - block: - name: download installer vars: @@ -21,13 +31,51 @@ import_role: name: installer/debian/preseed - - name: Copy the preseed initramfs to the artifacts directory + - name: Copy the preseed initramfs to the usb drive copy: src: "{{ tmpdir.path }}/initrd.preseed.gz" - dest: "{{ artifacts_dir }}/" + dest: "{{ usb_install_path }}/initrd.{{ install_hostname }}.gz" always: - name: Cleanup temporary workdir file: path: "{{ tmpdir.path }}" state: absent + +- name: Copy linux kernel image to the USB drive + copy: + src: "{{ global_cache_dir }}/debian-installer/{{ install_distro }}-{{ install_codename }}/{{ install.arch | default('amd64') }}/linux" + dest: "{{ usb_install_path }}/" + +- name: Generate syslinux configuration for BIOS boot + copy: + dest: "{{ usb_install_path }}/syslinux.cfg" + content: | + DEFAULT {{ install_hostname }} + TIMEOUT 100 + PROMPT 1 + SAY SYSLINUX booting an automated installer for {{ install_hostname }}... + + LABEL {{ install_hostname }} + KERNEL linux + INITRD initrd.{{ install_hostname }}.gz + APPEND install {{ (install.kernel_cmdline | default([])) | join(' ') }} + +- name: create EFI boot directory + file: + path: "{{ usb_install_path }}/EFI/boot" + state: directory + +- name: Generate syslinux configuration for UEFI boot + copy: + dest: "{{ usb_install_path }}/EFI/boot/syslinux.cfg" + content: | + DEFAULT {{ install_hostname }} + TIMEOUT 100 + PROMPT 1 + SAY SYSLINUX booting an automated installer for {{ install_hostname }}... + + LABEL {{ install_hostname }} + KERNEL ../../linux + INITRD ../../initrd.{{ install_hostname }}.gz + APPEND install {{ (install.kernel_cmdline | default([])) | join(' ') }} -- cgit v1.2.3