summaryrefslogtreecommitdiffstats
path: root/roles/bootstrap/tasks/install-archlinux.yml
blob: 9e36e70a6794b697214814c720474801c8160819 (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
---
- name: "Run pacstrap"
  ansible.builtin.command:
    cmd: "pacstrap -K {{ mnt_root_path }} base linux linux-firmware"
  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: "Clean up old Linux Boot Manager entries"
  ansible.builtin.shell:
    cmd: |
      for entry in $(efibootmgr | grep "Linux Boot Manager" | cut -d'*' -f1 | tr -d 'Boot'); do
        efibootmgr -b $entry -B
      done
  changed_when: false
  failed_when: false

# NOTE: bootctl is not run in chroot to workaround https://github.com/systemd/systemd/issues/36174
- name: "Run bootctl"
  ansible.builtin.command:
    cmd: "bootctl install --esp-path={{ mnt_boot_path }}"
  changed_when: true

- name: "Enable systemd-boot-update"
  ansible.builtin.command:
    cmd: "arch-chroot {{ mnt_root_path }} systemctl enable systemd-boot-update"
  changed_when: false

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

- name: "Create distro kernel directory"
  ansible.builtin.file:
    path: "{{ mnt_boot_path }}/archlinux"
    state: "directory"
    mode: "0755"

- name: "Copy kernel to efi partition"
  ansible.builtin.copy:
    src: "{{ item }}"
    dest: "{{ mnt_boot_path }}/archlinux/"
    remote_src: true
    mode: "0644"
  loop:
    - "{{ mnt_root_path }}/boot/vmlinuz-linux"
    - "{{ mnt_root_path }}/boot/initramfs-linux.img"
    - "{{ mnt_root_path }}/boot/initramfs-linux-fallback.img"

- name: "Configure pacman hook for updating kernel"
  ansible.builtin.copy:
    dest: "{{ mnt_root_path }}/etc/pacman.d/100-systemd-boot.hook"
    mode: "0644"
    content: |
      [Trigger]
      Type = Package
      Operation = Upgrade
      Target = linux

      [Action]
      Description = Updating systemd-boot
      When = PostTransaction
      Exec = /usr/bin/cp /boot/vmlinuz-linux /boot/efi/archlinux/vmlinuz-linux
      Exec = /usr/bin/cp /boot/initramfs-linux.img /boot/efi/archlinux/initramfs-linux.img
      Exec = /usr/bin/cp /boot/initramfs-linux-fallback.img /boot/efi/archlinux/initramfs-linux-fallback.img

- name: "Configure pacman in chroot"
  ansible.builtin.copy:
    src: "/etc/pacman.conf"
    dest: "{{ mnt_root_path }}/etc/pacman.conf"
    remote_src: true
    force: false
    mode: "0644"

- name: "Configure system in chroot"
  ansible.builtin.command:
    cmd: "arch-chroot {{ mnt_root_path }} {{ item }}"
  changed_when: true
  loop:
    - "pacman-key --init"
    - "pacman-key --populate"
    - "pacman -Syyu --noconfirm"

- name: "Ensure ansible dependencies are installed in chroot"
  ansible.builtin.command:
    cmd: "arch-chroot {{ mnt_root_path }} pacman -S --noconfirm python3"
  changed_when: true