# connection\_type lxd and remote machine?

**URL:** <https://forum.ansible.com/t/connection-type-lxd-and-remote-machine/23559>\
**Category:** Ansible Project\
**Tags:** ubuntu\
**Created:** [January 25, 2017, 4:40pm UTC](https://forum.ansible.com/t/connection-type-lxd-and-remote-machine/23559 "2017-01-25T16:40:54Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Hadmut\_Danisch](https://avatars.discourse-cdn.com/v4/letter/h/e99b99/32.png) [@Hadmut\_Danisch](https://forum.ansible.com/u/Hadmut_Danisch)\
**Post date:** [January 25, 2017, 4:40pm UTC](https://forum.ansible.com/t/connection-type-lxd-and-remote-machine/23559/1 "2017-01-25T16:40:54Z")

</div>

Hi,

if I have a machine running in an Ubuntu lxd container (without a sshd ), I can tell ansible in the inventory something like

someserver ansible\_connection=lxd

which makes ansible use the lxc exec command instead of ssh. This works if the ansible and the lxd host are running on the same machine.

But how would I tell ansible to do that (without annoying delegates in every single task) to access the container if lxd is running on a different machine?

e.g.

A machine running ansible with ssh access to B

B machine running a sshd and lxd

someserver a lxd container without sshd running on B

without delegate clauses (playbook should run for different targets, not all on lxd)

regards 🙂

---

<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:** [January 25, 2017, 8:46pm UTC](https://forum.ansible.com/t/connection-type-lxd-and-remote-machine/23559/2 "2017-01-25T20:46:14Z")

</div>

On the Ansible control machine add a remote lxd host as described here  
[https://www.stgraber.org/2016/04/12/lxd-2-0-remote-hosts-and-container-migration-612/](https://www.stgraber.org/2016/04/12/lxd-2-0-remote-hosts-and-container-migration-612/)

Then in you inventory file if you called the remote foo, you can do this

someserver ansible\_connection=lxd ansible\_host=foo:someserver

Then you can use host1 in the playbook as usual.

---

<div class="post-metadata">

**Author:** ![Hadmut\_Danisch](https://avatars.discourse-cdn.com/v4/letter/h/e99b99/32.png) [@Hadmut\_Danisch](https://forum.ansible.com/u/Hadmut_Danisch)\
**Post date:** [January 26, 2017, 2:32pm UTC](https://forum.ansible.com/t/connection-type-lxd-and-remote-machine/23559/3 "2017-01-26T14:32:00Z")

</div>

Thanks for the hint, but unfortunately that’s a nogo here, since opening a LXD port over untrusted networks is not an accepted procedure.

I would need something like ‘go with ssh onto foo and use the lxc commands then to do things on someserver’.

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [January 26, 2017, 2:39pm UTC](https://forum.ansible.com/t/connection-type-lxd-and-remote-machine/23559/4 "2017-01-26T14:39:36Z")

</div>

You cannot stack connections, so you either expose lxd (you can secure this) or you execute Ansible on the lxc host.
