aboutsummaryrefslogtreecommitdiff
path: root/bootstrap_arch_container.yml
blob: a5a11231ea42bd14708e28dd7447793d07e0507f (plain)
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
---
- name: Set local path facts
  set_fact:
    image: "/var/lib/machines/{{ container }}.img"
    root: "/var/lib/machines/{{ container }}"
    "{{container}}_root": "/var/lib/machines/{{ container }}"

- name: Create container image file
  command: truncate -s 4G "{{image}}"
  args:
      creates: "{{image}}"
  register: create_container

- name: Download arch bootstrap image
  get_url:
      url: http://mirror.rackspace.com/archlinux/iso/2021.12.01/archlinux-bootstrap-2021.12.01-x86_64.tar.gz
      dest: /tmp/arch-bootstrap.tar.xz
      checksum: sha256:d3d6d346001cd8a202fe5cc895897b54cc0edfc96790dd8d56888389d8a810e7
  when: create_container is changed

- name: Create container image filesystem
  filesystem:
      dev: "{{image}}"
      fstype: btrfs

- name: Create container image fstab entry
  mount:
      src: "{{image}}"
      path: "{{root}}"
      state: mounted
      fstype: btrfs
      opts: loop

- name: Unpack bootstrap image
  unarchive:
      remote_src: yes
      src: /tmp/arch-bootstrap.tar.xz
      dest: "{{root}}"
      extra_opts: --strip-components=1
      creates: "{{root}}/etc"

- name: Copy mirrorlist into container
  copy:
      src: mirrorlist
      dest: "{{root}}/etc/pacman.d/mirrorlist"

- name: Initialize container pacman keyring
  shell: arch-chroot "{{root}}" pacman-key --init && arch-chroot "{{root}}" pacman-key --populate archlinux
  args:
      creates: "{{root}}/etc/pacman.d/gnupg"

- name: Fixup pacman.conf for pacman to work in chroot without its own root fs
  lineinfile:
      path: "{{root}}/etc/pacman.conf"
      regexp: '^CheckSpace'
      line: '#CheckSpace'

- name: Update container keyring
  shell: arch-chroot "{{root}}" pacman -Sy --noconfirm archlinux-keyring

- name: Update container and install software
  shell: arch-chroot "{{root}}" pacman -Syu --noconfirm