ansible/usb-install: Automatically write relevant files to drive
authornicoo <nicoo@realraum.at>
Sat, 24 Nov 2018 19:48:32 +0000 (20:48 +0100)
committernicoo <nicoo@realraum.at>
Sat, 24 Nov 2018 23:30:33 +0000 (00:30 +0100)
ansible/usb-install.yml

index 20b3ae6..7ef386d 100644 (file)
@@ -2,12 +2,69 @@
 - name: Fetch debian installer and bake initrd
   hosts: "{{ hostname }}"
   connection: local
+
+  vars_prompt:
+    - name: usbdrive_path
+      prompt: Where is the USB installation medium mounted to?
+      default: ""
+      private: no
+
+  vars:
+    preseed_path: "{{ global_artifacts_dir }}/{{ hostname }}"
+    debian_installer_path: "{{ global_cache_dir }}/debian-installer"
+
   pre_tasks:
     - set_fact:
         install_cooked: "{{ install }}"
         network_cooked: "{{ network }}"
+
+    - file:
+        state: directory
+        name: "{{ item }}"
+      with_items:
+        - "{{ preseed_path }}"
+        - "{{ debian_installer_path }}"
+
   roles:
     - usb-install
-  vars:
-    preseed_path: "{{ global_artifacts_dir }}"
-    debian_installer_path: "{{ global_cache_dir }}/debian-installer"
+
+  tasks:
+    - stat:
+        path: "{{ usbdrive_path }}"
+      register: pathcheck
+
+    - when: pathcheck.stat.exists
+      block:
+        - name: Copy generated files to the USB drive
+          copy:
+            src: "{{ item.value }}"
+            dest: "{{ usbdrive_path }}/{{ item.key }}"
+          with_dict:
+            initrd.gz: "{{ global_artifacts_dir }}/{{ hostname }}/{{ hostname }}-{{ install_distro }}-{{ install_codename }}.initrd.gz"
+            linux: "{{ global_cache_dir }}/debian-installer/{{ install_distro }}-{{ install_codename }}/{{ install.arch | default('amd64') }}/linux"
+
+        - name: Generate syslinux configuration
+          copy:
+            dest: "{{ usbdrive_path }}/syslinux.cfg"
+            content: |
+              DEFAULT linux
+               SAY SYSLINUX booting an automated installer for {{ hostname }}...
+              LABEL linux
+               KERNEL linux
+               INITRD initrd.gz
+               APPEND install vga=off console=ttyS0,115200n8
+
+        - 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.]
+
+              This will NOT be done automatically.