#cloud-config

write_files:
  - path: /etc/systemd/network/10-eth0.network
    content: |
      [Match]
      Name=enp7s0

      [Network]
      DHCP=yes
      Gateway=10.0.0.1
      DNS=185.12.64.2
      DNS=185.12.64.1

  - path: /etc/netplan/50-cloud-init.yaml
    content: |
      network:
        version: 2
        ethernets:
          enp7s0:
            dhcp4: true
            routes:
              - to: default
                via: 10.0.0.1
            nameservers:
              addresses:
                - 185.12.64.2
                - 185.12.64.1

runcmd:
  - |
    echo "Restarting network"
    systemctl restart systemd-networkd
    echo "Checking if we can reach the internet"
    curl -Is https://google.com | head -n 1 | grep "200 OK" > /dev/null && echo "Internet access is up." || echo "Internet access is down."
    echo "Updating package cache"
    apt-get update -y
    echo "Upgrading packages"
    apt-get upgrade -y
    echo "Registering node with kubeadm"
    ${register_command} --etcd --controlplane --worker

users:
  - name: thomas
    sudo: ALL=(ALL) NOPASSWD:ALL
    shell: /bin/bash
    passwd: $6$gPaN6lngIIrrjMb1$wDrBxIDpGyJftsIQ5slQrEwXPxDOLXrFs2hGz640fyZLt1vSjtH8HPY6H4WwWpLKsKUEWCl/2hz4N57m98ESZ1
    lock_passwd: false
