aboutsummaryrefslogtreecommitdiff
blob: a39aa453a28747f85bcf14f03a616eccd3c8ce0e (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
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
---
- name: disks
  tags:
    - disks
  block:
  - name: check for mounted disk
    # Not perfect.
    ansible.builtin.command: "grep '{{ item }}' /proc/mounts"
    failed_when: false
    changed_when: false
    register: check_mounted_disk
    check_mode: no
    loop:
      - /dev/nvme0n1
      - /dev/nvme1n1
  
  - name: debug
    ansible.builtin.debug:
      msg: "{{ check_mounted_disk }}"
  
  - name: abort if disk mounted
    ansible.builtin.fail:
      msg: "Aborting install due to {{ item }} being mounted"
    when: item.rc == 0
    loop: "{{ check_mounted_disk.results }}"
  
  - name: write partition layout file
    ansible.builtin.copy:
      dest: /tmp/partition.sfdisk
      # RootFS on LVM
      content: |
        label: gpt
        p1 : start=1MiB, size=63MiB, type=uefi, name=EFI
        p2 : start=64MiB, size=448MiB, type=raid, name=BOOT
        p3 : start=512MiB, size=+, type=lvm, name=LVM
    tags:
      - partition
    
  - name: partition disks
    ansible.builtin.shell: "/usr/sbin/sfdisk {{ item }} </tmp/partition.sfdisk"
    loop:
      - /dev/nvme0n1
      - /dev/nvme1n1
    tags:
      - partition
  
  - name: fact md1 devices
    ansible.builtin.set_fact:
      md1_dev: "{{ ansible_loop.allitems|join(' ') }}"
    loop:
      - /dev/nvme0n1p1
      - /dev/nvme1n1p1
    loop_control:
      extended: true
    tags:
      - mdadm
  
  - name: fact md2 devices
    ansible.builtin.set_fact:
      md2_dev: "{{ ansible_loop.allitems|join(' ') }}"
    loop:
      - /dev/nvme0n1p2
      - /dev/nvme1n1p2
    loop_control:
      extended: true
    tags:
      - mdadm
  
  - name: mdadm p1
    ansible.builtin.command: "mdadm --create -e 1.0 /dev/md1 --level=raid1 -n 2 {{ md1_dev }}"
    tags:
      - mdadm
  
  - name: mdadm p2
    ansible.builtin.command: "mdadm --create -e 1.0 /dev/md2 --level=raid1 -n 2 {{ md2_dev }}"
    tags:
      - mdadm
  
  - name: format p1/mkfs
    ansible.builtin.command: "mkfs.fat -F 16 -n EFI {{ item }}"
    tags:
      - mkfs
    loop:
      - /dev/md1
  
  - name: format p2/mkfs
    ansible.builtin.command: "mkfs.ext4 -T floppy,news -L BOOT {{ item }}"
    loop:
      - /dev/md2
    tags:
      - mkfs
  
  - name: format p3/pvcreate
    ansible.builtin.command: "pvcreate {{ ansible_loop.allitems|join(' ') }}"
    loop_control:
      extended: true
    loop:
      - /dev/nvme0n1p3
      - /dev/nvme1n1p3
    tags:
      - lvm
      - pvcreate
  
  - name: fact vgcreate PVs
    ansible.builtin.set_fact:
      pvs: "{{ ansible_loop.allitems|join(' ') }}"
    loop:
      - /dev/nvme0n1p3
      - /dev/nvme1n1p3
    loop_control:
      extended: true
    tags:
      - lvm
      - vgcreate
  
  - name: fact vgs
    ansible.builtin.set_fact:
      vgs: "{{ hostname }}"
    tags:
      - disk
      - mount
      - lvm
  
  - name: vgcreate
    ansible.builtin.command: "vgcreate {{ hostname }} {{ pvs }}"
    tags:
      - lvm
      - vgcreate
  
  - name: lvcreate root
    ansible.builtin.command: "lvcreate --type raid1 -L 30g --name rootfs {{ vgs }}"
    tags:
      - lvm
      - lvcreate
  
  - name: mkfs root
    ansible.builtin.command: "mkfs.ext4 -T floppy,news -L ROOTFS /dev/{{ vgs }}/rootfs"
    tags:
      - rootfs
      - mkfs