#cloud-config
# vim: set ft=yaml:
autoinstall:
  version: 1
  network:  # Should disable networking, workaround for unattended-updates failing in install
    version: 2
  refresh-installer:
    update: yes
  keyboard:
    layout: us
  storage:
    config:
      - id: drive
        type: disk
        ptable: gpt
        name: hard-drive
        preserve: false
        grub_device: true
        wipe: superblock
      - id: bios-grub
        type: partition
        device: drive
        size: 1M
        flag: bios_grub
      - id: boot-partition
        type: partition
        device: drive
        size: 200M
        name: boot
      - id: swap-partition
        type: partition
        device: drive
        size: 10%
        name: swap
        flag: swap
      - id: root-partition
        type: partition
        device: drive
        name: root
        size: -1
      - id: boot-format
        type: format
        fstype: ext4
        volume: boot-partition
        label: boot
        preserve: false
      - id: swap-format
        type: format
        fstype: swap
        volume: swap-partition
        label: swap
        preserve: false
      - id: root-format
        type: format
        fstype: ext4
        volume: root-partition
        label: root
        preserve: false
      - type: mount
        id: root-mount
        device: root-format
        path: /
      - type: mount
        id: boot-mount
        device: boot-format
        path: /boot
      - type: mount
        id: swap-mount
        device: swap-format
        path: none
  identity:
    hostname: vagrant
    username: vagrant
    password: $6$rounds=4096$mJTRlY/vwPMquLe0$s4Ld3ZnvF.pM86xzbAgQD7Xpi/NMVgyQNb5CEfabFgL6nLRsP56WtwA.o.Jg/xC6HaJmM2p5fCGIo37jmKVRI0
  ssh:
    install-server: yes
    authorized_keys:
      - ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA6NF8iallvQVp22WDkTkyrtvp9eWW6A8YVr+kz4TjGYe7gHzIw+niNltGEFHzD8+v1I2YJ6oXevct1YeS0o9HZyN1Q9qgCgzUFtdOKLv6IedplqoPkcmF0aYet2PkEDo3MlTBckFXPITAMzF8dJSIFo9D8HfdOV0IAdx4O7PtixWKn5y2hMNG0zQPyUecp4pzC6kivAIhyfHilFR61RGL+GPXQ2MWZWFYbAGjyiYJnAmCP3NOTd0jMZEnDkbUvxhMmBYSdETk1rRgm+R4LOzFUGaHqHDLKLX+FIPKcF96hrucXzcWyLbIbEgE98OHlnVYCzRdK8jlqm8tehUc9c9WhQ== vagrant insecure public key
    allow-pw: yes
  user-data:
    disable_root: false
  late-commands:
    - echo 'Defaults:vagrant !requiretty' > /target/etc/sudoers.d/vagrant
    - echo 'vagrant ALL=(ALL) NOPASSWD:ALL' >> /target/etc/sudoers.d/vagrant
    - chmod 440 /target/etc/sudoers.d/vagrant
    # Restore network after bypassing unattended updates
    - "echo -n 'network:\n  version: 2\n  ethernets:\n    eth0:\n      dhcp4: true\n      dhcp-identifier: mac' > /target/etc/netplan/00-installer-config.yaml"
    - netplan apply
    - sed -i -E -e 's/GRUB_CMDLINE_LINUX="(.*)"/GRUB_CMDLINE_LINUX="net.ifnames=0 biosdevnames=0\1"/' /target/etc/default/grub
    - mount -o bind /dev /target/dev
    - mount -o bind /sys /target/sys
    - mount -o bind /proc /target/proc
    - chroot /target /usr/sbin/update-grub
  packages:
    - curl
    - sudo
