Skip to content

Latest commit

 

History

History
57 lines (29 loc) · 1.62 KB

ubuntu_cloud-config_with_lxd.md

File metadata and controls

57 lines (29 loc) · 1.62 KB

Ubuntu cloud-config with LXD {#ubuntu-cloud-config-with-lxd}

By default, LXD already uses ubuntu-cloudimg images. These are the same images used on Amazon AWS or Digital Ocean Public Clouds.

If you’ve not used Ubuntu on a Public Cloud before you may not know about the feature/capability called “cloud-init” or “cloud-config”. This capability allows you to preconfigure specific OS features/packages/etc when the Cloud instance is first started.

The information you pre-configure is termed “user-data”.

What you may not know is that with LXD that same capability exists for the LXC containers you create.

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. By “ephemeral” is meant that the LXC container will be deleted automatically when you “stop” it.

To create/install “user-data” create a file named .yaml. The name can be anything.

Then start the LXC container:

$ lxc launch ubuntu:16.04 cn2 -c user.user-data="$(cat .yaml)"

That is all there is to it.

Here is an example of a configuration:

#cloud-config

output:

all: "|tee -a /tmp/cloud.out"

#hostname: {{ hostname }}

bootcmd:

  • rm -f /etc/dpkg/dpkg.cfg.d/multiarch

apt_sources:

  • source: ppa:yellow/ppa

ssh_import_id: [evarlast] # use -S option

packages:

  • make

final_message: "The system is finally up, after $UPTIME seconds"

runcmd: