Anybody working on ansible modules for lxd?

lxd is the new container system which is included by default in ubuntu 16.04:
https://linuxcontainers.org/lxd/

Unlike docker, lxd containers are essentially lightweight VMs, with their own init daemon, sshd etc, and typically on a static IP address.

I’d like an ansible to:

(1) Handle lifecycle management: create/configure, start and stop lxd containers; install lxd profiles.

(2) Be able to execute commands within a container using “lxc exec ” - so you don’t have to set up an ssh trust relationship with the container. Something like “ansible_connection=lxd” in the inventory.

This could be done by shelling out to the “lxc xxx” commands (confusingly prefixed lxc not lxd). Alternatively, lxd also has a proper API you can talk to, with a python client too.
https://linuxcontainers.org/lxd/rest-api/

Using the CLI you can control remote hosts using “:” as the container name. Using the REST API you connect directly to the host of interest.

Is there any work going on in this area? All I’ve been able to find is an ansible module for installing lxd itself on your host platform.

Thanks,

Brian.

On the developer list Hiroaki Nakamura posted this on May 10:

<quote>
I created the lxd_container Ansible module and sent a pull request to
the ansible-modules-extra project.

"Add lxd_container module by hnakamur · Pull Request #2208 ·
ansible/ansible-modules-extras"
https://github.com/ansible/ansible-modules-extras/pull/2208

Could you take a look at the pull request and send me a feedback?
Any feedbacks are welcome.
</quote>

I don’t have time to actually test it today.

Looking at the code/features: this looks like a good starting point. It is missing the ability to create or update a profile (idempotently) which is something I’ll need.

A separate desirable feature would be “ansible_connection=lxd”, using:
https://github.com/lxc/lxd/blob/master/doc/rest-api.md#10containersnameexec

https://github.com/lxc/lxd/blob/master/doc/rest-api.md#10containersnamefiles

but I don’t know if that can be done in a module, or needs to be in the core.

Anyway, I’ll try out the module as it is, as soon as I get a chance.

Regards,

Brian.

An lxd connection plugin will be included in Ansible 2.1 which just had an RC2 release a few days ago.

So it should already be usable in ansible 2.2.0 devel? Super.

Yep, just tested it. Thank you!!

There is also a dynamic inventory script build on the REST api here on GitHub: https://github.com/june07/Ansible-LXDynamic-Inventory