summaryrefslogtreecommitdiffstats
path: root/roles/bootstrap/tasks/install-archlinux.yml
blob: 441d448e69479f604b6feb2491c7065a9c1dea69 (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
101
102
103
104
105
106
107
108
109
110
111
112
---
- name: "Refresh mirrorlist"
  ansible.builtin.command:
    # CDN edges (e.g. fastly.mirror.pkgbuild.com) drop SSL on large downloads; pick working mirrors
    cmd: reflector --latest 5 --sort rate --protocol https --save /etc/pacman.d/mirrorlist
  changed_when: true

- name: "Update live environment"
  ansible.builtin.command:
    cmd: "{{ item }}"
  loop:
    - "pacman -Sy --needed archlinux-keyring --noconfirm"
  changed_when: true

- name: "Run pacstrap"
  ansible.builtin.command:
    cmd: "pacstrap -K {{ mnt_root_path }} base linux linux-firmware less nano"
  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 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 rEFInd package installed"
  ansible.builtin.command:
    cmd: "arch-chroot {{ mnt_root_path }} pacman -S --noconfirm refind"
  changed_when: true

- name: "Install rEFInd to EFI partition"
  ansible.builtin.command:
    # NOTE: --usedefault installs to EFI/BOOT/ without NVRAM registration
    # This ensures consistent install location across refind versions (0.13.x installs to EFI/refind/
    # via NVRAM, 0.14.x falls back to EFI/BOOT/ when NVRAM write fails in chroot)
    cmd: "arch-chroot {{ mnt_root_path }} refind-install --usedefault {{ partition_boot.dev }}"
  changed_when: true

- name: "Configure rEFInd base settings"
  ansible.builtin.template:
    src: "refind.conf.j2"
    dest: "{{ mnt_boot_path }}/EFI/BOOT/refind.conf"
    mode: "0644"
  # NOTE: this is skipped because the docker test doesn't have proper EFI/BOOT directory created
  tags: ["molecule-notest"]

- name: "Ensure arch EFI boot directory exists"
  ansible.builtin.file:
    path: "{{ mnt_boot_path }}/EFI/arch"
    state: directory
    mode: "0755"

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

- name: "Configure Arch Linux boot entries"
  ansible.builtin.template:
    src: "archlinux/archlinux.conf.j2"
    dest: "{{ mnt_boot_path }}/EFI/BOOT/archlinux.conf"
    mode: "0644"
  # NOTE: this is skipped because the docker test doesn't have proper EFI/BOOT directory created
  tags: ["molecule-notest"]

- name: "Install kernel sync script for EFI partition"
  ansible.builtin.template:
    src: "archlinux/refind-sync-kernel.j2"
    dest: "{{ mnt_root_path }}/usr/local/bin/refind-sync-kernel"
    mode: "0755"

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

      [Action]
      Description = Syncing kernel to EFI partition after kernel update
      When = PostTransaction
      Exec = /usr/local/bin/refind-sync-kernel

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