Content¶
For containers, the rootfs directory (or tarball) contains a full file
system tree of what will become the /
. For VMs, this is instead a
rootfs.img
file which becomes the main disk device.
The templates directory contains pongo2-formatted templates of files inside the instance.
metadata.yaml
contains information relevant to running the image
under LXD, at the moment, this contains:
architecture: x86_64
creation_date: 1424284563
properties:
description: Ubuntu 18.04 LTS Intel 64bit
os: Ubuntu
release: bionic 18.04
templates:
/etc/hosts:
when:
- create
- rename
template: hosts.tpl
properties:
foo: bar
/etc/hostname:
when:
- start
template: hostname.tpl
/etc/network/interfaces:
when:
- create
template: interfaces.tpl
create_only: true
The architecture
and creation_date
fields are mandatory, the
properties are just a set of default properties for the image. The os,
release, name and description fields while not mandatory in any way,
should be pretty common.
For templates, the when
key can be one or more of:
create
(run at the time a new instance is created from the image)copy
(run when an instance is created from an existing one)start
(run every time the instance is started)
The templates will always receive the following context:
trigger
: name of the event which triggered the template (string)path
: path of the file being templated (string)container
: key/value map of instance properties (name, architecture, privileged and ephemeral) (map[string]string) (deprecated in favor ofinstance
)instance
: key/value map of instance properties (name, architecture, privileged and ephemeral) (map[string]string)config
: key/value map of the instance’s configuration (map[string]string)devices
: key/value map of the devices assigned to this instance (map[string]map[string]string)properties
: key/value map of the template properties specified in metadata.yaml (map[string]string)
The create_only
key can be set to have LXD only only create missing
files but not overwrite an existing file.
As a general rule, you should never template a file which is owned by a package or is otherwise expected to be overwritten by normal operation of the instance.
For convenience the following functions are exported to pongo templates:
config_get("user.foo", "bar")
=> Returns the value ofuser.foo
or"bar"
if unset.