summaryrefslogtreecommitdiffstats
path: root/roles/bootstrap/tasks/install-ubuntu.yml
blob: f1c28d7ff93a3dfdac61593906198e81904979d7 (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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
---
- name: "Include distribution vars"
  ansible.builtin.include_vars: "{{ ansible_distribution | lower }}.yml"

- name: "Ensure install dependencies are installed on live environment"
  ansible.builtin.apt:
    state: "present"
    update_cache: true
    pkg:
      - "debootstrap"
      - "arch-install-scripts"
      - "bash"

- name: "Run debootstrap"
  ansible.builtin.command:
    cmd: "debootstrap
      {{ bootstrap_opts }}
      {{ bootstrap_distro.name }}
      {{ mnt_root_path }}
      {{ bootstrap_distro.mirror_url }}"
  changed_when: true

- name: "Generate fstab"
  ansible.builtin.shell:
    cmd: "genfstab -t PARTLABEL {{ mnt_root_path }} > {{ mnt_root_path }}/etc/fstab"
  changed_when: true

- name: "Configure apt in chroot"
  ansible.builtin.copy:
    dest: "{{ item.dest }}"
    mode: "0640"
    content: "{{ item.content }}"
  with_items:
    - dest: "{{ mnt_root_path }}/etc/apt/preferences.d/ignored-package"
      content: "{{ bootstrap_apt_ignored_preferences }}"
    - dest: "{{ mnt_root_path }}/etc/apt/sources.list"
      content: "{{ bootstrap_apt_sources }}"

- name: "Configure system in chroot"
  ansible.builtin.command:
    cmd: "arch-chroot {{ mnt_root_path }} {{ item }}"
  changed_when: true
  with_items:
    - "apt-get update"
    - "apt-get install -y {{ bootstrap_distro.packages | join(' ') }}"

- name: "Run bootclt"
  ansible.builtin.command:
    cmd: "arch-chroot {{ mnt_root_path }} bootctl install"
  changed_when: true

- name: "Get machine-id"
  ansible.builtin.command:
    cmd: "cat {{ mnt_root_path }}/etc/machine-id"
  changed_when: false
  register: bootstrap_machine_id

- name: "Get Kernel version"
  ansible.builtin.shell: |
    set -eo pipefail
    ls {{ mnt_root_path }}/boot/vmlinuz-* | sed 's/.*vmlinuz-//'
  args:
    executable: /usr/bin/bash
  changed_when: false
  register: bootstrap_kernel_version

- name: "Create distro kernel directory"
  ansible.builtin.file:
    path: "{{ mnt_boot_path }}/{{ ansible_distribution | lower }}"
    state: "directory"
    mode: "0700"

- name: "Copy kernel to efi partition"
  ansible.builtin.copy:
    src: "{{ item }}"
    dest: "{{ mnt_boot_path }}/{{ ansible_distribution | lower }}"
    remote_src: true
    mode: "0644"
  with_items:
    - "{{ mnt_root_path }}/boot/vmlinuz-{{ bootstrap_kernel_version.stdout }}"
    - "{{ mnt_root_path }}/boot/initrd.img-{{ bootstrap_kernel_version.stdout }}"

- name: "Template systemd-boot files"
  ansible.builtin.template:
    src: "{{ item.src }}"
    dest: "{{ item.dest }}"
    mode: "0644"
  with_items:
    - src: "loader.conf.j2"
      dest: "{{ mnt_boot_path }}/loader/loader.conf"
    - src: "{{ ansible_distribution | lower }}.conf.j2"
      dest: "{{ mnt_boot_path }}/loader/entries/{{ ansible_distribution | lower }}.conf"

- name: "Clean up debian kernel install"
  ansible.builtin.file:
    path: "{{ item }}"
    state: "absent"
  with_items:
    - "{{ mnt_boot_path }}/{{ bootstrap_machine_id.stdout }}"
    - "{{ mnt_boot_path }}/loader/entries/{{ bootstrap_machine_id.stdout }}-{{ bootstrap_kernel_version.stdout }}.conf"