Cloud-init with netplan

Can’t get a gadget with cloud.conf to work.

If I snap a gadget containing cloud.conf whose content is:

#cloud-config
write_files:
  - encoding: 64
    content: |
      bmV0d29yazoKICB2ZXJzaW9uOiAyCiAgZXRoZXJuZXRzOgogICAgZXRoMDoKICAgICAgYWRkcmVzc2VzOgogICAgICAgIC0gMTAuMC4wLjI0NC8yNAogICAgICBnYXRld2F5NDoKICAgICAgICAxMC4wLjAuMQogIHdpZmlzOgogICAgd2xhbjA6CiAgICAgIGRoY3A0OgogICAgICAgIHRydWUKICAgICAgYWNjZXNzLXBvaW50czoKICAgICAgICAiYXN0cm9fZ2FyZGVuXzIiOgogICAgICAgICAgcGFzc3dvcmQ6CiAgICAgICAgICAgICJ1YnVudHV1YnVudHUi
    owner: root:root
    path: /etc/netplan/01-cloud-init.yaml
    permissions: '0644'

I do not end up with that file created after boot (although cloud-init was enabled in the image). It does end up in /etc/cloud/cloud.cfg, and I can see that being read in journal:

... util.py[DEBUG]: Read 497 bytes from /etc/cloud/cloud.cfg
... util.py[DEBUG]: Attempting to load yaml from string of length 497 with allowed root types (<class 'dict'>,)
... util.py[DEBUG]: Reading from /run/cloud-init/cloud.cfg (quiet=False)

But I finally get the standard /etc/netplan/00-snapd-config.yaml that defines network, not my netplan file from the gadget cloud.conf.

I based that write_files approach on https://cloudinit.readthedocs.io/en/latest/topics/examples.html#writing-out-arbitrary-files

Couple other points:

  • I’d like to use cloud-init’s native ability to declare network config (instead of write_files). In the case of core, seems like the approach would be Network Config Version 2 (https://cloudinit.readthedocs.io/en/latest/topics/network-config.html). But this is said to not support the netplan “wifis” key, which I need. It’s not clear to me whether there is another viable option for core.

  • Giving up on the gadget approach for now, I also tried using a cloud.conf file passed to ubuntu-image with --cloud-config FILE. Unexpectedly, the resulting image seems to have cloud-init disabled:

$ ls mnt/system-data/etc/cloud/
cloud-init.disabled

So, I am so far unable to use the gadget snap cloud.conf to configure netplan with wifi. I see no other way but to mount the image and add my netplan file (as above).