Dynamic Cloud-init

Hello,
I’m testing Rancher in last release (v2.4.8) with vsphere as cloud-provider.

When I create a cluster, I need to have for my nodes, some specific configuration like static IP, DNS, NTP and so on. “Cloud-init” is able to do this. I tested by passing a URL to get “cloud-init” file and it’s working fine.

I would like to use one template for all my nodes. But I want to configure static IP address for each. So, to construct my “cloud-init” file, I need more informations like “node name”. Is it possible to add dynamic parameter to URL used to get “cloud-init” file in the template node?

The idea is to have something like: “http://my.site.com/cloud-init.php?nodename=$nodename”.

Thanks for your help,
Yannael

Note: for now I don’t want to use a tool like Terraform to provision nodes and create cluster. My goal is to use only Rancher!

Hi,
I’m using a different approach to achieve the same result, so I thought I might share it.

I have a static cloud-init script that uses the environment passed through the vmware-tools guestInfo interface, and then I use network protocol profiles on vCenter to allocate IP addresses in that subnet. This way it works fine and you don’t get any issues such as you would get using DHCP, and if you replace a node (or add a node) it just gets a new IP automatically. I find it very simple, I’ve found this approach on some article and tested it extensively, never had a problem so far.

Hope this helps,
Daniele

P.S. If you are interested let me know and I can share the script and some screenshots

Hi Daniele,
Thanks for your feedback! I already had a look to this solution. But it is not optimal for my infrastructure… I don’t want to be dependant of VMWare configuration. I also need to make other things completly dependant of our infrastructure (like reserved IP in our IPAM, …).
I didn’t try yet the method you propose. It should be a great solution if I’m not able to do what I want! I’m interseted to get your script if it is possible.

Thanks a lot,
Yannael

Hi Yannael,

sure thing, if you don’t find a more suitable solution you can try this one.

I’m attaching the cloud-init script and a screenshot of the ovf settings you have to configure in order for this to work.

#cloud-config
write_files:
  - path: /root/netplan.sh
    content: |
        #!/bin/bash
        vmtoolsd --cmd 'info-get guestinfo.ovfEnv' > /tmp/ovfenv
        IPAddress=$(sed -n 's/.*Property oe:key="guestinfo.interface.0.ip.0.address" oe:value="\([^"]*\).*/\1/p' /tmp/ovfenv)
        SubnetMask=$(sed -n 's/.*Property oe:key="guestinfo.interface.0.ip.0.netmask" oe:value="\([^"]*\).*/\1/p' /tmp/ovfenv)
        Gateway=$(sed -n 's/.*Property oe:key="guestinfo.interface.0.route.0.gateway" oe:value="\([^"]*\).*/\1/p' /tmp/ovfenv)
        DNS=$(sed -n 's/.*Property oe:key="guestinfo.dns.servers" oe:value="\([^"]*\).*/\1/p' /tmp/ovfenv)
        cat > /etc/netplan/01-netcfg.yaml <<EOF
        network:
          version: 2
          renderer: networkd
          ethernets:
            ens192:
              addresses: 
                - $IPAddress/$SubnetMask
              gateway4: $Gateway
              nameservers:
                addresses : [$DNS]
        EOF
 
        sudo netplan apply
runcmd:
  - bash /root/netplan.sh

I hope this helps,
Daniele

Thanks a lot, I will try soon!
Yannaël

Hi ildanish,

Could you please share your work ?

Thank you!