# Anybody working on ansible modules for lxd?

**URL:** <https://forum.ansible.com/t/anybody-working-on-ansible-modules-for-lxd/21444>\
**Category:** Ansible Project\
**Tags:** ubuntu\
**Created:** [May 15, 2016, 8:29am UTC](https://forum.ansible.com/t/anybody-working-on-ansible-modules-for-lxd/21444 "2016-05-15T08:29:27Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Brian\_Candler](https://avatars.discourse-cdn.com/v4/letter/b/5f9b8f/32.png) [@Brian\_Candler](https://forum.ansible.com/u/Brian_Candler)\
**Post date:** [May 15, 2016, 8:29am UTC](https://forum.ansible.com/t/anybody-working-on-ansible-modules-for-lxd/21444/1 "2016-05-15T08:29:27Z")

</div>

lxd is the new container system which is included by default in ubuntu 16.04:  
[https://linuxcontainers.org/lxd/](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/](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.

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [May 15, 2016, 9:12am UTC](https://forum.ansible.com/t/anybody-working-on-ansible-modules-for-lxd/21444/2 "2016-05-15T09:12:05Z")

</div>

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](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\>

---

<div class="post-metadata">

**Author:** ![Brian\_Candler](https://avatars.discourse-cdn.com/v4/letter/b/5f9b8f/32.png) [@Brian\_Candler](https://forum.ansible.com/u/Brian_Candler)\
**Post date:** [May 15, 2016, 12:32pm UTC](https://forum.ansible.com/t/anybody-working-on-ansible-modules-for-lxd/21444/3 "2016-05-15T12:32:57Z")

</div>

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#10containersnameexec)

[https://github.com/lxc/lxd/blob/master/doc/rest-api.md#10containersnamefiles](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.

---

<div class="post-metadata">

**Author:** ![sivel](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sivel/32/1198_2.png) [@sivel](https://forum.ansible.com/u/sivel)\
**Post date:** [May 15, 2016, 2:13pm UTC](https://forum.ansible.com/t/anybody-working-on-ansible-modules-for-lxd/21444/4 "2016-05-15T14:13:22Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Brian\_Candler](https://avatars.discourse-cdn.com/v4/letter/b/5f9b8f/32.png) [@Brian\_Candler](https://forum.ansible.com/u/Brian_Candler)\
**Post date:** [May 17, 2016, 9:39am UTC](https://forum.ansible.com/t/anybody-working-on-ansible-modules-for-lxd/21444/5 "2016-05-17T09:39:15Z")

</div>

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

Yep, just tested it. Thank you!!

---

<div class="post-metadata">

**Author:** ![will](https://avatars.discourse-cdn.com/v4/letter/w/90ced4/32.png) [@will](https://forum.ansible.com/u/will)\
**Post date:** [October 10, 2016, 3:50pm UTC](https://forum.ansible.com/t/anybody-working-on-ansible-modules-for-lxd/21444/6 "2016-10-10T15:50:17Z")

</div>

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