user.meta-data
doesn’t get merged, it’s a different much more limited format that pretty much just tells cloud-init what the instance name and id is. In the new world, meta-data
cannot be altered by the user anymore (that’s why it doesn’t have a cloud-init.meta-data
equivalent).
Any news? How to apply cloud-init.user-data
consistently from many profiles or may be to merge they today?
There hasn’t been a change to this.
You can have at most two Incus profiles with cloud-init
instructions.
One profile would list those instructions in a user.user-data
and the other profile in a user.vendor-data
section. Then, by specifying both these two profiles when launching an instance, you would get these cloud-init
instructions merged together.
The command line could look like the following.
incus launch images:debian/12/cloud --profile default --profile addwebserver --profile adddatabaseserver
I tested it and for me don’t work (( what am I doing wrong?
I created two profiles:
incus profile create vendor
incus profile create user
and created content of these profiles:
incus profile set vendor cloud-init.vendor-data - << EOF
#cloud-config
runcmd:
- echo DISPLAY="$DISPLAY" >> /etc/environment
- echo WAYLAND_DISPLAY="$WAYLAND_DISPLAY" >> /etc/environment
write_files:
- path: /home/ubuntu/vendor-content.txt
permissions: 0755
content: |
vendor content
EOF
incus profile set user cloud-init.user-data - << EOF
#cloud-config
write_files:
- path: /home/ubuntu/user-content.txt
permissions: 0755
content: |
user content
runcmd:
- echo XDG_SESSION_TYPE="wayland" >> /etc/environment
- echo QT_QPA_PLATFORM="wayland" >> /etc/environment
EOF
Then launched the container:
incus create ubuntu2310cloud websurf --profile=vendor --profile=user
incus start websurf
After finished cloud-init
:
incus exec websurf -- su -l ubuntu -c 'cloud-init analyze show'
I got configuration only last profile (user). Why? Env variables created only from user
profile:
incus exec websurf -- su -l ubuntu -c 'cat /etc/environment'
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin"
XDG_SESSION_TYPE=wayland
QT_QPA_PLATFORM=wayland
and only one file created in home directory. The file vendor-content.txt
is missed:
incus exec websurf -- su -l ubuntu -c 'ls -l $HOME'
total 4
-rwxr-xr-x 1 root root 13 Apr 3 10:54 user-content.txt
Have a look in the container in the directory /var/lib/cloud/seed/nocloud-net/
.
The files are in there, verbatim, just as they came from the Incus profile.
debian@mycloud:/var/lib/cloud/seed/nocloud-net$ ls -l
total 4
-rw-r--r-- 1 root root 46 Apr 3 11:33 meta-data
-rw-r--r-- 1 root root 107 Apr 3 11:33 network-config
-rw-r--r-- 1 root root 230 Apr 3 11:33 user-data
-rw-r--r-- 1 root root 213 Apr 3 11:33 vendor-data
debian@mycloud:/var/lib/cloud/seed/nocloud-net$
This means that now cloud-init
took over, has the proper user-data
and vendor-data
files and can do its magic. It’s off the hands of Incus.
I tried your instructions. It looks like cloud-init
might perform some merging of its own. Because it runs part of the user-data
and part of the vendor-data
.
I didn’t understand. Is it now impossible to merge cloud-init.vendor-data
and cloud-init.user-data
? It now don’t work?
Incus does what is required so that the cloud-init.vendor-data
and cloud-init.user-data
are placed in the container at the proper location ( /var/lib/cloud/seed/nocloud-net
) for cloud-init
to do its magic.
I do not have deep knowledge of cloud-init; you would need to check the logs or perhaps enable more detailed logs to figure out what’s going on.
Your example files are mostly fine. I wouldn’t put my test files in /home/ubuntu/ because I am not sure in what sequence the non-root account is created. There’s a possibility that /home/ubuntu has not been created yet.
Ok, thanks! But env variables to /etc/environment
also don’t sets from my cloud-init.vendor-data
, so I think it’s not a matter of ubuntu user that hasn’t been created yet. I will look at the logs of cloud-init
The incus documentation says:
If both
vendor-data
anduser-data
are supplied for an instance,cloud-init
merges the two configurations. However, if you use the same keys in both configurations, merging might not be possible. In this case, configure howcloud-init
should merge the provided data. See Merging user data sections for instructions.
Both your configs are providing “runcmd” and “write_files”, so if you don’t want one to overwrite the other, you need to tell cloud-init how to merge them, as per this example.