I use cloud-config files to configure all my instances, but I don’t use cloud-init. Instead, I have written a tool that applies cloud-config files to instances using the Incus or LXD API (like “incus exec” and “incus file push” do). That way I don’t need to use images that have cloud-init, and I can apply such cloud-config scripts to running instances at any time, not only when they are launched.
I have implemented 4 cloud-config modules: packages, write_files, users, runcmd. These are enough for my configuration needs.
For example, to create the file “/tmp/I_was_here” in instance C, use this test.cfg file:
#cloud-config
runcmd:
- touch /tmp/I_was_here
or this:
#cloud-config
runcmd:
- [ "touch", "/tmp/I_was_here2" ]
or this:
#cloud-config
write_files:
- path: /tmp/I_was_here3
content: |
Indeed.
I was.
and run:
lxops cloudconfig -f test.cfg C
or
lxops cloudconfig -i C test.cfg
You can find the Go source of this tool at GitHub - melato/lxops
It does several other things related to launching and configuring containers, but you can just use the “cloudconfig” command.
@simos, You’ve tried to compile a predecessor of this tool before, and it did not compile. I’ve simplified the compilation process since then, and I added the cloudconfig command. I just compiled it in a new Debian container with Go:
git clone https://github.com/melato/lxops
cd lxops/impl/incus/main
go install lxops-incus.go
Then rename the resulting lxops-incus to lxops.