M HYPE SPLASH
// updates

How do I use cloud-init to apply netplan?

By Michael Henderson

After I manually edit /etc/cloud/cloud.cfg.d/50-curtin-networking.cfg, how do I tell cloud-init to update /etc/netplan/50-cloud-init.yaml? In other words, it doesn't make sense to manually update both files; what's the standard process to re-apply the netplan?

2 Answers

The cloud-init confuguration files are not the place the change your network configuration after first boot, because the network configuration will only be generated once by cloud-init (on first boot).

You can however change the netplan config file directly. Then use the following commands as root to enable your changes. They will stick across boots.

netplan generate
netplan apply

Only the command 'cloud-init clean' will regenerate the 50...yaml file, but I dont think you want that. That would reset everything, including hostname en machine-id (resulting in a new max-address and a new dhcp ip address).

2

As Lismatro said, once you create your netplan config, generate then apply it.

In your cloud-init config, first tells netplan to use custom config:

write_files:
- path: /etc/cloud/cloud.cfg.d/99-custom-networking.cfg permissions: '0644' content: | network: {config: disabled}

Then create the netplan config (still in cloud-init config). Here is a simple example. Find more ways to configure network interfaces with netplan here:

- path: /etc/netplan/my-new-config.yaml permissions: '0644' content: | network: version: 2 ethernets: ens3: dhcp4: true

Finally tell cloud-init to use it (again, still in cloud-init config):

runcmd: - rm /etc/netplan/50-cloud-init.yaml - netplan generate - netplan apply

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy