#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 %} write_files: - content: | #!/bin/bash apt-get -y -q purge cloud-init cloud-guest-utils cloud-initramfs-copymods cloud-initramfs-dyn-netconf sosreport update-notifier-common ubuntu-pro-client {% 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 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' rm -f /root/post-cleanup.sh {% if ubuntu_autoinstall_poweroff_when_done %} poweroff {% else %} reboot {% endif %} path: /root/post-cleanup.sh permissions: '0755' runcmd: - ['systemd-run', '-p', 'StandardOutput=journal+console', '--on-active=10', '/root/post-cleanup.sh'] 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\s\s*[0-9][0-9]*$/Port {{ ansible_port }}/' -i /etc/ssh/sshd_config - curtin in-target --target=/target -- bash -c "mkdir -p /etc/systemd/system/ssh.socket.d; echo -e '[Socket]\nListenStream=\nListenStream={{ ansible_port }}' > /etc/systemd/system/ssh.socket.d/port.conf" {% endif %} - curtin in-target --target=/target -- apt-get -y -q purge multipath-tools open-vm-tools {% if (install_codename | ubuntu_release_compare('>=', 'jammy')) %} - curtin in-target --target=/target -- apt-get -y -q purge systemd-oomd {% endif %} {% 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 ubuntu-advantage-tools sound-theme-freedesktop thin-provisioning-tools cryptsetup byobu open-iscsi btrfs-progs pollinate lxd-agent-loader ufw {% if (install_codename | ubuntu_release_compare('>=', 'noble')) %} - curtin in-target --target=/target -- apt-get -y -q purge ubuntu-kernel-accessories {% endif %} {% 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 %}