#cloud-config
autoinstall:
  version: 1
  identity:
    hostname: ubuntu-server
    password: '$6$wdAcoXrU039hKYPd$508Qvbe7ObUnxoj15DRCkzC3qO7edjH0VV7BPNRDYK4QR8ofJaEEF2heacn0QgD.f8pO8SNp83XNdWG6tocBM1'
    username: ubuntu
  network:
      network:
          version: 2
          ethernets:
              eth0:
                 dhcp4: yes
  early-commands:
    # otherwise packer tries to connect and exceed max attempts:
    - systemctl stop ssh
  packages:
    - ca-certificates
    - cloud-guest-utils
    - cloud-init
  ssh:
    install-server: true
    allow-pw: yes
    storage:
        swap:
            size: 0
        config:
            - { type: disk, id: disk-0, ptable: gpt, wipe: superblock-recursive, grub_device: true }
            - { type: partition, id: partition-0, number: 1, device: disk-0, size: 1M, wipe: superblock, flag: bios_grub }
            - { type: partition, id: partition-1, number: 2, device: disk-0, size: 4096M, wipe: superblock, flag: boot }
            - { type: partition, id: partition-2, number: 3, device: disk-0, size: 8192M, wipe: superblock, flag: swap }
            - { type: partition, id: partition-3, number: 4, device: disk-0, size: -1, wipe: superblock }
            - { type: format, id: format-0, volume: partition-1, fstype: ext4 }
            - { type: format, id: format-1, volume: partition-2, fstype: swap }
            - { type: format, id: format-2, volume: partition-3, fstype: ext4 }
            - { type: mount, id: mount-0, device: format-0, path: /boot }
            - { type: mount, id: mount-1, device: format-1, path: none }
            - { type: mount, id: mount-2, device: format-2, path: / }
  late-commands:
      - echo 'ubuntu ALL=(ALL) NOPASSWD:ALL' > /target/etc/sudoers.d/ubuntu
      - |
        curtin in-target --target=/target -- /bin/bash -c ' \
            sed -ie "s/^[#\s]*UseDNS.*$/UseDNS no/g" /etc/ssh/sshd_config; \
            ssh-keygen -A; \
            systemctl enable ssh.service; \
            sed -ie "s/^GRUB_DEFAULT=.*/GRUB_DEFAULT=\"0\"/g" /etc/default/grub; \
            sed -ie "s/^GRUB_CMDLINE_LINUX=.*/GRUB_CMDLINE_LINUX=\"net.ifnames=0 biosdevname=0 systemd.unified_cgroup_hierarchy=0\"/g" /etc/default/grub; \
            sed -ie "s/^GRUB_CMDLINE_LINUX_DEFAULT=.*/GRUB_CMDLINE_LINUX_DEFAULT=\"net.ifnames=0 biosdevname=0 systemd.unified_cgroup_hierarchy=0\"/g" /etc/default/grub; \
            update-grub; \
            update-initramfs -c -k all; \
            exit 0 \
        '