How to check if "lxd init --auto" already ran?


is there some way to see that lxd init --auto already ran? I am asking for the following reason. I want to use this in an Ansible playbook. In Ansible a task will usually check if the state into which it would bring the system has already been reached. If that is the case, the task won’t change a thing.

In order to achieve that, I’d need to be able to check if lxd init --auto had been run prior to the task run.

Unfortunately even if containers are already running, I only get:

# lxd init --auto
LXD has been successfully configured.

Is there a way to verify that lxd init --auto was run before?


In some of my reading and experimentation, I found that running lxd init --auto was not strictly necessary, and so in writing a chef resource for this, I took on the tactic of “If I did the install, then I’ll do the lxd init”. And that’s been working well for me on fresh Ubuntus, and remains safe if the recipe gets applied to a pre-existing installation of lxd.

But, I’d still like to hear if there is a more deterministic method. I’ve had thoughts such as testing for the existence of the $LXD_DIR/lxd.db, but my resource calls lxc info as part of it’s startup/inspection phase, which causes lxd to auto generate its folder structure. (Is lxd doing lxd init --auto internally, in this case?)

On old LXD (2.0.x mostly), lxd init is indeed not required and LXD will be mostly functional without it.

On newer LXD releases, lxd init is how most people configure storage and network, without which, you won’t be able to start containers.

On such recent releases, you can’t easily tell if lxd init was run, especially as lxd init can now be run multiple times. But what you can do is check for what matters to you.

Typically, that’s that the default profile contains a network device and a root disk.

Ah, thanks. That’s a viable method indeed. So I needn’t worry to get any errors when querying the default profile, I take it?

LXD if running will always let you query everything even if not fully configured, so you should be fine.