12

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 2

4

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
1
  • thank you, good sir, I was looking for this to find out why my cloud-init configuration was not applying Dec 26, 2023 at 3:30
2

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
  • 13
    My netplan file says this at the top: " # This file is generated from information provided by # the datasource. Changes to it will not persist across an instance. # To disable cloud-init's network configuration capabilities, write a file # /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg with the following: # network: {config: disabled} " It's still ok to edit this file?
    – user988346
    Mar 15, 2020 at 22:30
  • For an explanation on the "not across an instance" warning, refer to my answer at askubuntu.com/questions/1117469/…
    – Lismatro
    Jun 9, 2022 at 19:46

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .