summaryrefslogtreecommitdiff
path: root/roles/installer/ubuntu/autoinstall/templates/autoinstall.yml.j2
blob: 125e8d8203cab47c54ec56690db33257d7baac73 (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
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
#cloud-config
autoinstall:
  version: 1
  early-commands:
  - python3 /cdrom/autoinstall/early-command.py

  locale: "{{ ubuntu_autoinstall_locale }}"
  keyboard:
    layout: "{{ ubuntu_autoinstall_keyboard_layout }}"
    variant: "{{ ubuntu_autoinstall_keyboard_variant }}"
    toggle: null

  network:
    version: 2
    ethernets:
      {{ install_interface | default(network.primary.name) }}:
{% if install_dhcp | default(false) %}
        dhcp4: yes
{% else %}
        addresses:
        - {{ network.primary.address }}
        gateway4: {{ network.primary.gateway }}
{%   if (network.nameservers  | default([]) | length) > 0 %}
        nameservers:
          search: [ {{ host_domain }} ]
          addresses: [ {{ network.nameservers | join(', ') }} ]
{%   endif %}
{% endif %}

{% if ubuntu_autoinstall_manual_partitioning %}
  interactive-sections:
  - storage

{% else %}
  storage:
    config:
{%   if install.disks.primary != "software-raid" %}
    - id: disk-primary
      type: disk
      path: {{ install.disks.primary }}
{%     if install.efi | default(false) %}
      ptable: gpt
{%     else %}
      ptable: msdos
      grub_device: true
{%     endif %}
      wipe: superblock-recursive
{%   else %}
{%     for raid_member in install.disks.raid.members %}
    - id: raid-disk{{ loop.index }}
      type: disk
      path: {{ raid_member }}
{%       if install.efi | default(false) %}
      ptable: gpt
{%       else %}
      ptable: msdos
      grub_device: true
{%       endif %}
      wipe: superblock-recursive
{%     endfor %}
{%   endif %}

{%   if install.efi | default(false) %}
{%     set part_offset = 1 %}
{%     if install.disks.primary != "software-raid" %}
    - id: partition-esp
      type: partition
      device: disk-primary
      flag: boot
      number: 1
      size: {{ ubuntu_autoinstall_efi_esp_size | human_to_bytes }}
      grub_device: true
    - id: format-esp
      type: format
      volume: partition-esp
      label: efi
      fstype: fat32
    - id: mount-esp
      type: mount
      device: format-esp
      path: /boot/efi
{%     else %}
{%       for raid_member in install.disks.raid.members %}
    - id: partition-esp{{ loop.index }}
      type: partition
      device: raid-disk{{ loop.index }}
      flag: boot
      number: 1
      size: {{ ubuntu_autoinstall_efi_esp_size | human_to_bytes }}
      grub_device: true
    - id: format-esp{{ loop.index }}
      type: format
      volume: partition-esp{{ loop.index }}
      label: efi
      fstype: fat32
    - id: mount-esp{{ loop.index }}
      type: mount
      device: format-esp{{ loop.index }}
      path: /boot/efi
{%       endfor %}
{%     endif %}

{%   else %}
{%     set part_offset = 0 %}
{%   endif %}
{%   if install.disks.primary == "software-raid" %}
{%     for raid_member in install.disks.raid.members %}
    - id: raid-partition-boot{{ loop.index }}
      type: partition
      device: raid-disk{{ loop.index }}
      number: {{ part_offset + 1 }}
      size: {{ ubuntu_autoinstall_swraid_boot_size | human_to_bytes }}
{%     endfor %}
    - id: partition-boot
      type: raid
      name: md-boot
      raidlevel: {{ install.disks.raid.level }}
      devices:
{%     for raid_member in install.disks.raid.members %}
      - raid-partition-boot{{ loop.index }}
{%     endfor %}
    - id: format-boot
      type: format
      volume: partition-boot
      fstype: ext4
    - id: mount-boot
      type: mount
      device: format-boot
      path: /boot
{%     set part_offset = part_offset + 1 %}

{%   endif %}
{%   set system_lvm_size = install.system_lvm.size | default(ubuntu_autoinstall_system_lvm_size_default) %}
{%   set system_lvm_volumes = install.system_lvm.volumes | default(ubuntu_autoinstall_system_lvm_volumes_default) %}
{%   if install.disks.primary != "software-raid" %}
    - id: partition-lvm
      type: partition
      device: disk-primary
      flag: linux
      number: {{ part_offset + 1 }}
{%     if system_lvm_size != 'all' %}
      size: {{ system_lvm_size | human_to_bytes }}
    - id: partition-unused
      type: partition
      device: disk-primary
      flag: linux
      number: {{ part_offset + 2 }}
{%     endif %}
      size: -1

{%   else %}
{%     for raid_member in install.disks.raid.members %}
    - id: raid-partition-lvm{{ loop.index }}
      type: partition
      device: raid-disk{{ loop.index }}
      number: {{ part_offset + 1 }}
{%       if system_lvm_size != 'all' %}
      size: {{ system_lvm_size | human_to_bytes }}
    - id: raid-partition-unused{{ loop.index }}
      type: partition
      device: raid-disk{{ loop.index }}
      flag: linux
      number: {{ part_offset + 2 }}
{%       endif %}
      size: -1
{%     endfor %}
    - id: partition-lvm
      type: raid
      name: md-lvm
      raidlevel: {{ install.disks.raid.level }}
      devices:
{%     for raid_member in install.disks.raid.members %}
      - raid-partition-lvm{{ loop.index }}
{%     endfor %}

{%   endif %}
    - id: lvm-vg-system
      type: lvm_volgroup
      devices:
      - partition-lvm
      name: {{ host_name }}

{%   for volume in system_lvm_volumes %}
    - id: lvm-lv-{{ volume.name }}
      type: lvm_partition
      volgroup: lvm-vg-system
      name: {{ volume.name }}
      size: {{ volume.size | human_to_bytes }}
    - id: format-{{ volume.name }}
      type: format
      fstype: {{ volume.filesystem }}
      volume: lvm-lv-{{ volume.name }}
    - id: mount-{{ volume.name }}
      type: mount
      device: format-{{ volume.name }}
      path: {{ volume.mountpoint }}
{%     if 'mount_options' in volume and (volume.mount_options | length) > 0 %}
      options: '{{ volume.mount_options | join(",") }}'
{%     endif %}

{%   endfor %}
{% endif %}
  apt:
    primary:
    - uri: http://{{ apt_repo_providers[apt_repo_provider].ubuntu.host }}{{ apt_repo_providers[apt_repo_provider].ubuntu.path }}
      arches:
      - amd64

  user-data:
    hostname: "{{ host_name }}"
    timezone: "{{ ubuntu_autoinstall_timezone }}"
    disable_root: false
    users:
    - name: root
      ssh_authorized_keys:
{% for key in ssh_keys_root %}
      - {{ key }}
{% endfor %}
    runcmd:
    - [ apt-get, -y, -q, purge, cloud-init, cloud-guest-utils, cloud-initramfs-copymods, cloud-initramfs-dyn-netconf, sosreport, update-notifier-common ]
{% if ubuntu_autoinstall_desktop is undefined %}
    - [ apt-get, -y, -q, purge, snapd, python3-cryptography, gpg, ssh-import-id ]
{% endif %}
    - [ rm, -rf, /etc/cloud, /var/lib/cloud ]
    - [ apt-get, -y, -q, auto-remove ]
    - [ bash, -c, 'dpkg -l | grep "^rc" | awk "{ print(\$2) }" | xargs -r dpkg -P' ]
    - [ sed, '/^PasswordAuthentication /d', -i, '/etc/ssh/sshd_config' ]
    - [ rm, -f, '/etc/ssh/sshd_config.d/50-cloud-init.conf' ]
{% if ubuntu_autoinstall_poweroff_when_done %}
    - [ poweroff ]
{% else %}
    - [ reboot ]
{% endif %}

  ssh:
    install-server: true

  packages:
  - python3
  - python3-apt
{% if ubuntu_autoinstall_desktop is defined %}
  - {{ ubuntu_autoinstall_desktop }}-desktop^
{% endif %}
{% for task in ubuntu_autoinstall_install_tasks %}
  - {{ task }}^
{% endfor %}

  late-commands:
  - curtin in-target --target=/target -- swapoff -a; sed -e '/^\/swapfile/d' -e '/^\/swap\.img/d' -i /etc/fstab; rm -f /swapfile /swap.img
{% if ansible_port is defined %}
  - curtin in-target --target=/target -- sed -e 's/^\(\s*#*\s*Port.*\)/Port {{ ansible_port }}/' -i /etc/ssh/sshd_config
{% endif %}
  - curtin in-target --target=/target -- apt-get -y -q purge multipath-tools open-vm-tools
  - curtin in-target --target=/target -- apt-get -y -q purge systemd-oomd
{% if ubuntu_autoinstall_desktop is undefined %}
  - curtin in-target --target=/target -- apt-mark manual iputils-ping isc-dhcp-client netcat-openbsd netplan.io sudo
  - curtin in-target --target=/target -- apt-get -y -q purge policykit-1 ubuntu-minimal unattended-upgrades sound-theme-freedesktop thin-provisioning-tools cryptsetup byobu open-iscsi btrfs-progs pollinate lxd-agent-loader ufw
{%   if install.disks.primary != "software-raid" %}
  - curtin in-target --target=/target -- apt-get -y -q purge mdadm
{%   endif %}
  - curtin in-target --target=/target -- env SUDO_FORCE_REMOVE=yes apt-get -y -q purge sudo
{% endif %}
  - curtin in-target --target=/target -- apt-get -y -q autoremove
  - curtin in-target --target=/target -- bash -c 'dpkg -l | grep "^rc" | awk "{ print(\$2) }" | xargs -r dpkg -P'
{% if ubuntu_autoinstall_desktop is undefined %}
{# purging the snapd package here would trigger a bug in den postrm script because some filesystems in /run/ can not be unmounted... #}
{# to workadound this issue we only remove the package here and rely on cloud-init to fully purge it on first boot (see user-data: above) #}
  - curtin in-target --target=/target -- apt-get -y -q remove snapd
{% endif %}
  - curtin in-target --target=/target -- bash -c 'apt-get update -q && apt-get full-upgrade -y -q'
{% if ubuntu_autoinstall_kernel_image is defined or ubuntu_autoinstall_virtual_machine %}

write_files:
  - path: /run/kernel-meta-package
    content: |
{%   if ubuntu_autoinstall_kernel_image is defined %}
      {{ ubuntu_autoinstall_kernel_image }}
{%   else %}
      linux-virtual
{%   endif %}
    owner: root:root
    permissions: "0644"
{% endif %}