Cloud-config with LXD

A year ago I wrote

Since then, LXD became the best way to use LXC.

By default, LXD already uses ubuntu-cloudimg images.

The lesser know feature is using cloud-config with LXD. It turns out it is very easy to pass user-data to an LXD instance when you start it, just like you would on any cloud provider.

LXD even has the -e option to make your LXD instance ephemeral. It will be deleted automatically when you stop it.

Just like in that previous blog post, I create a file named one.yaml. The name can be anything. Then i start it:

lxc launch ubuntu:14.04 crisp-Hadley -c user.user-data="$(cat one.yaml)"

That is all there is to it.

Here is an example of config similar to what I used recently to QA a build configuration:

 all: "|tee -a /tmp/cloud.out"
#hostname: {{ hostname }}
 - rm -f /etc/dpkg/dpkg.cfg.d/multiarch
 - source: ppa:yellow/ppa
ssh_import_id: [evarlast] # use -S option
 - make
final_message: "The system is finally up, after $UPTIME seconds"
 - cd /home/ubuntu
 - git clone
 - cd myproject
 - make deps run