How to get the full configuration to use it with lxd init --preseed

After I set up LXD manually via lxd init I’d like to get the full contents of my configuration in YAML format so I can then use it in script/ Ansible with lxd init --preseed option.
lxc profile show default shows only the profliesettings, how about the rest?

1 Like

Here is the code in LXD that prints the preseed when you interactively run sudo lxd init,

A few lines later in the code, it does the following and extracts a YAML representation of the configuration.

out, err := yaml.Marshal(object)

The configuration (in object object) has been built using the helper functions of the form AskStorage(), AskNetwork() and so on.

Here is a sample preseed from running sudo lxd init in a container:

config: {}
cluster: null
networks:
- config:
    ipv4.address: auto
    ipv6.address: auto
  description: ""
  managed: false
  name: lxdbr0
  type: ""
storage_pools:
- config: {}
  description: ""
  name: default
  driver: dir
profiles:
- config: {}
  description: ""
  devices:
    eth0:
      name: eth0
      nictype: bridged
      parent: lxdbr0
      type: nic
    root:
      path: /
      pool: default
      type: disk
  name: default

You can build up the preseed file by using lxc commands, for the network, the storage, the profiles, and the cluster.

The part about the network requires some manual editing, because it looks like

ubuntu@preseed:~$ lxc network show lxdbr0
config:
  ipv4.address: 10.97.106.1/24
  ipv4.nat: "true"
  ipv6.address: fd42:207b:e88:eb67::1/64
  ipv6.nat: "true"
description: ""
name: lxdbr0
type: bridge
used_by: []
managed: true
status: Created
locations:
- none
ubuntu@preseed:~$

The following commands can give you the skeleton for the preseed file,

lxc config show
lxc cluster show mycluster
lxc network show lxdbr0
lxc storage show default
lxc profile show default

As an alternative, I would create a LXD container with security.nesting and run in there sudo lxd init to setup LXD. When I am asked about the preseed output, I would ask to have it printed so that I get a copy to keep for later.

2 Likes

Thank you very much! I hope you put that in your blog as well, for better SEO so more people could find it.

stgraber@castiana:~$ lxd init --dump
config:
  candid.api.url: https://services.stgraber.org/identity
  candid.domains: stgraber.net
  core.debug_address: 127.0.0.1:8444
  core.https_address: :8443
networks:
- config:
    ipv4.address: 10.166.11.1/24
    ipv4.nat: "true"
    ipv6.address: 2001:470:b368:4242::1/64
    ipv6.nat: "true"
  description: ""
  managed: true
  name: lxdbr0
  type: bridge
storage_pools:
- config:
    source: /var/lib/lxd/storage-pools/blah
  description: ""
  name: blah
  driver: dir
- config:
    size: 33GB
    source: castiana/lxd
    zfs.pool_name: castiana/lxd
  description: ""
  name: default
  driver: zfs
- config:
    source: /var/lib/lxd/storage-pools/dir
  description: ""
  name: dir
  driver: dir
profiles:
- config:
    user.vendor-data: |
      #cloud-config
      apt_mirror: http://us.archive.ubuntu.com/ubuntu/
  description: Default LXD profile
  devices:
    eth0:
      name: eth0
      nictype: bridged
      parent: lxdbr0
      type: nic
    root:
      path: /
      pool: default
      type: disk
  name: default
4 Likes

That is… surprisingly intentional. Thanks!

How do you actually use the lxd init --preseed?
By the lxd init --dump you can get the output of default setup from lxd init, but how do you direct it using the preseed command?

1 Like

lxd init --preseed < input.yaml

2 Likes

dpkg -l | grep lxd

ii lxd 3.0.3-0ubuntu1~18.04.2 amd64 Container hypervisor based on LXC - daemon
ii lxd-client

lxd init --dump

Error: unknown flag: --dump

That version is too old, you should use the current 5.0 LTS or higher.