ansible/usb-install: Automatically write relevant files to drive
[noc.git] / ansible / usb-install.yml
1 ---
2 - name: Fetch debian installer and bake initrd
3   hosts: "{{ hostname }}"
4   connection: local
5
6   vars_prompt:
7     - name: usbdrive_path
8       prompt: Where is the USB installation medium mounted to?
9       default: ""
10       private: no
11
12   vars:
13     preseed_path: "{{ global_artifacts_dir }}/{{ hostname }}"
14     debian_installer_path: "{{ global_cache_dir }}/debian-installer"
15
16   pre_tasks:
17     - set_fact:
18         install_cooked: "{{ install }}"
19         network_cooked: "{{ network }}"
20
21     - file:
22         state: directory
23         name: "{{ item }}"
24       with_items:
25         - "{{ preseed_path }}"
26         - "{{ debian_installer_path }}"
27
28   roles:
29     - usb-install
30
31   tasks:
32     - stat:
33         path: "{{ usbdrive_path }}"
34       register: pathcheck
35
36     - when: pathcheck.stat.exists
37       block:
38         - name: Copy generated files to the USB drive
39           copy:
40             src: "{{ item.value }}"
41             dest: "{{ usbdrive_path }}/{{ item.key }}"
42           with_dict:
43             initrd.gz: "{{ global_artifacts_dir }}/{{ hostname }}/{{ hostname }}-{{ install_distro }}-{{ install_codename }}.initrd.gz"
44             linux: "{{ global_cache_dir }}/debian-installer/{{ install_distro }}-{{ install_codename }}/{{ install.arch | default('amd64') }}/linux"
45
46         - name: Generate syslinux configuration
47           copy:
48             dest: "{{ usbdrive_path }}/syslinux.cfg"
49             content: |
50               DEFAULT linux
51                SAY SYSLINUX booting an automated installer for {{ hostname }}...
52               LABEL linux
53                KERNEL linux
54                INITRD initrd.gz
55                APPEND install vga=off console=ttyS0,115200n8
56
57         - name: Make the USB disk bootable
58           pause:
59             seconds: 0
60             prompt: |
61               You should make sure the USB disk is bootable and
62               has syslinux installed.
63
64               $ sudo apt install mbr syslinux
65               $ sudo install-mbr /dev/CHANGEME
66               $ sudo syslinux -i /dev/CHANGEME1
67               $ sudo fdisk       /dev/CHANGEME
68               [Here, make sure partition 1 is marked bootable.]
69
70               This will NOT be done automatically.