Configuring Private IP in startup script

I need to be able to automatically configure the private IP for my instances. Once the instance is spun, I realize that the Sample Network Configuration is generated with some examples.

I'm using an Ubuntu 18 based image.

The question is how do I generate the 10-ens3.yaml and 10-ens7.yaml in the startup script with the correct values?

Comments

  • edited May 4

    You can access that information in a startup script using the Vultr Metadata API. There is an example in this document:

    https://www.vultr.com/docs/vultr-startup-scripts-quickstart-guide

  • For Ubuntu 18.04:

    apt update
    apt install -y jq
    private_ip="$(curl -s http://169.254.169.254/v1.json | jq '.interfaces[1].ipv4.address' | tr -d '"')"
    echo "network:
      version: 2
      renderer: networkd
      ethernets:
        ens7:
          mtu: 1450
          dhcp4: no
          addresses: [$private_ip/16]" > /etc/netplan/10-ens7.yaml
    netplan apply
    
Sign In or Register to comment.