Where does hostname.tpl come from?

Hi,

I’m quite new to lxd and seem to be unable to locate the doco that will tell me how to get a template into an image I created following https://tutorials.ubuntu.com/tutorial/create-custom-lxd-images#0 … I’d like to modify the hostname of a container on launch.

Cheers,
Tink

OK, so I ripped apart an exported image from ubuntu: … there’s a template directory next to rootfs, which explains some things; hoping to get that name-issue sorted real soon now ;0

Is there a way to include arbitrary shell commands in templates? The reason I’m asking is that we use static IPs for all long-lived machines (be they bare metal, VMs or containers). For VMs and bare-metal deployments via foreman I can pull IP info from DNS; I’d like to do the same for lxd - have my /etc/netplan/01-netcfg.yaml configured on launch.

Cheers

take a look here

or at @simos’s blogs here https://blog.simos.info/how-to-preconfigure-lxd-containers-with-cloud-init/

But in reality the method with cloud-config is not very reliable for daily business. One workaround I figured out is to create a container from an image of your choice, configure it with a minimum of your needs and stop the container. Then copy it for a new container like »lxc copy container newcontainer«. Both containers are not running. Next do a »zfs list« to get your containers-storage place and »zfs mount container-stroage/newcontainer«. Now you can copy a prepared “interfaces”-file into the newcontainer in “/var/snap/lxd/common/lxd/storage-pools/default/containers/newcontainer/etc/network/” directly. This done you can start the new container and it will be up with the new ip-address .
Afterwards you can install &| configure your newcontainer by a script using i.e.

lxc exec – sh -c “cd /tmp”

In addition, there is a gradual shift (almost completed?) to using distrobuilder to create container images. LXD’s container images will be created using distrobuilder.

With distrobuilder, you use a configuration file like

with is versatile enough to help you insert additional functionality to the container image.

I have written two posts on distrobuilder (The LXD tutorials of Simos).

Thanks Simos for the valuable resources and the responses as such! I think I have this sorted… sometimes I just need to bash my head against a wall a little longer (kill bad braincells? :D) to get an epiphany.

I ended up w/ two simple templates that I put in a directory templates by the side of rootfs, added those to metadata.yaml and verified them working. Now I just need to write a little python wrapper to reduce the typing required with the lxc launch and I’m away laughing.

Cheers,
Tink