summaryrefslogtreecommitdiff
path: root/roles/installer/ubuntu/usb/tasks/main.yml
blob: 94b7c316c0efae9d84968c3a5571be290a86deee (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
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.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