summaryrefslogtreecommitdiff
path: root/roles/installer/ubuntu/autoinstall/templates/autoinstall.yml.j2
blob: 97b54b0a40f01a1c8f5b1e2172cb8a9a304813d8 (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
#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_cooked.primary.name) }}:
{% if install_dhcp | default(false) %}
        dhcp4: yes
{% else %}
        addresses:
        - {{ network_cooked.primary.address }}
        gateway4: {{ network_cooked.primary.gateway }}
{%   if (network_cooked.nameservers  | default([]) | length) > 0 %}
        nameservers:
          search: [ {{ host_domain }} ]
          addresses: [ {{ network_cooked.nameservers | join(', ') }} ]
{%   endif %}
{% endif %}

  storage:
    config:
    - id: disk-primary
      type: disk
      path: {{ install_cooked.disks.primary }}
{% if install_cooked.efi | default(false) %}
      ptable: gpt
{% else %}
      ptable: msdos
      grub_device: true
{% endif %}
      wipe: superblock-recursive

{% if install_cooked.efi | default(false) %}
{%   set part_offset = 1 %}
    - 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 %}
{%   set part_offset = 0 %}

{% endif %}
{% set system_lvm_size = install_cooked.system_lvm.size | default(ubuntu_autoinstall_system_lvm_size_default) %}
{% set system_lvm_volumes = install_cooked.system_lvm.volumes | default(ubuntu_autoinstall_system_lvm_volumes_default) %}
    - 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

    - 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 %}
  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, snapd, cloud-init, cloud-guest-utils, cloud-initramfs-copymods, cloud-initramfs-dyn-netconf, python3-cryptography, gpg, sosreport, update-notifier-common, ssh-import-id ]
    - [ rm, -rf, /etc/cloud, /var/lib/cloud ]
    - [ apt-get, -y, -q, auto-remove ]
    - [ bash, -c, 'dpkg -l | grep "^rc" | awk "{ print(\$2) }" | xargs dpkg -P' ]
{% if ubuntu_autoinstall_virtual_machine %}
    - [ poweroff ]
{% endif %}

  ssh:
    install-server: true

  packages:
  - python3
  - python3-apt
{% for task in ubuntu_autoinstall_install_tasks %}
  - {{ task }}^
{% endfor %}

  late-commands:
  - curtin in-target --target=/target -- swapoff -a; sed -e '/^\/swapfile/d' -i /etc/fstab; rm -f /swapfile
{% 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-mark manual iputils-ping isc-dhcp-client netcat-openbsd netplan.io sudo
  - curtin in-target --target=/target -- apt-get -y -q purge policykit-1 multipath-tools ubuntu-minimal unattended-upgrades sound-theme-freedesktop thin-provisioning-tools cryptsetup mdadm byobu open-iscsi btrfs-progs pollinate lxd-agent-loader
{% if not ubuntu_autoinstall_virtual_machine %}
  - curtin in-target --target=/target -- apt-get -y -q purge open-vm-tools
{% endif %}
  - curtin in-target --target=/target -- env SUDO_FORCE_REMOVE=yes apt-get -y -q purge sudo
  - 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 dpkg -P'
{# 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
  - 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 %}