Cloud-init configuration and pylxd

Not strictly speaking a LXD error but when I create a container via a pylxd script the cloud-init commands don’t appear to have any effect.

I’ve created a profile which has config.user.user-data populated…

config:
  user.user-data: "#cloud-config\npackage_upgrade: true\npackages:\n  - build-essential\ntimezone: Europe/London\nruncmd: \n  - [touch, /tmp/hello_world]\n"
description: Cloud-init Profile

This command works:-

# lxc launch 'ubuntu:focal'  test -p default -p cidata -p zpool

However in my pylxd script…
When I create a container with default, cidata and zpool profiles whilst it creates the container the cidata cloud-config is ignored…

Running the same create from the command line using lxc does work…

Does this mean the cloud-init is done in lxc and not in the RESTAPI?

Thanks in advance?

There is no interface other than the REST API. The lxc tool is just a REST client.

If your container doesn’t have the user.user-data config key set in lxc config show NAME after your creation as described above, then it means the key wasn’t properly set as part of the config dict. If it’s set but is somehow mangled, then that’s another kind of problem :slight_smile:

That’s good to know…

So follow my logic here… I have a profile called cidata (detailed above) and if I use lxc launch it works and cloud-init is fired off…

But if create the same container using pylxd container.create() method it creates the same container but cloud-init doesn’t work.

Same profile (unchanged)…

The only difference is that the base image is different… Let me check…

Ah I think I see the problem… The working cloud init is from…
“source”: {
“type”: “image”,
“certificate”: “”,
“alias”: “focal”,
“server”: “https://cloud-images.ubuntu.com/releases”,
“protocol”: “simplestreams”,
“mode”: “pull”
},

but my python script is using…

type: ‘image’
mode: ‘pull’
protocol: ‘simplestreams’
server: ‘https://images.linuxcontainers.org
alias: ‘ubuntu/focal’

I bet that is the issue…

Subtle…

Yes that was the issue… :poop:

thank you <3