# remote access to lxc containers on lxc-host without ssh inside the containers

**URL:** <https://forum.ansible.com/t/remote-access-to-lxc-containers-on-lxc-host-without-ssh-inside-the-containers/23546>\
**Category:** Ansible Project\
**Created:** [January 24, 2017, 11:38am UTC](https://forum.ansible.com/t/remote-access-to-lxc-containers-on-lxc-host-without-ssh-inside-the-containers/23546 "2017-01-24T11:38:08Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mario\_Keller](https://avatars.discourse-cdn.com/v4/letter/m/90ced4/32.png) [@Mario\_Keller](https://forum.ansible.com/u/Mario_Keller)\
**Post date:** [January 24, 2017, 11:38am UTC](https://forum.ansible.com/t/remote-access-to-lxc-containers-on-lxc-host-without-ssh-inside-the-containers/23546/1 "2017-01-24T11:38:08Z")

</div>

Hello,

I’m trying to configure lxc containers via ansible running on a remote host. I have ssh access to the remote host, but inside the containers there are no ssh services running. There is a lxc connection plugin that handle access to the containers via lxc-attach but it seems that this works only on the lxc-host.

There is also third party plugin ([https://github.com/chifflier/ansible-lxc-ssh](https://github.com/chifflier/ansible-lxc-ssh)) that should to this via an ssh connection, but it does not work (was written for ansible 2.0 with last update over 11 months ago) and also need direct root access to the remote machine (no sudo after ssh connect). So this is also no option.

Is there a way for the built in lxc connector to be used remote?

I could manage the config for all containers in a git repo and use ansible in my local machine to trigger “git pull” and “ansible-playbook runs” on the remote lxc-host to configure the containers, but it would be nice if there’s a simpler way to do this.

---

<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 25, 2017, 12:19am UTC](https://forum.ansible.com/t/remote-access-to-lxc-containers-on-lxc-host-without-ssh-inside-the-containers/23546/2 "2017-01-25T00:19:08Z")

</div>

look at lxd connection plugin, IIRc it allows for remote connections

---

<div class="post-metadata">

**Author:** ![Pshem\_Kowalczyk](https://avatars.discourse-cdn.com/v4/letter/p/e480ec/32.png) [@Pshem\_Kowalczyk](https://forum.ansible.com/u/Pshem_Kowalczyk)\
**Post date:** [January 25, 2017, 12:19am UTC](https://forum.ansible.com/t/remote-access-to-lxc-containers-on-lxc-host-without-ssh-inside-the-containers/23546/3 "2017-01-25T00:19:35Z")

</div>

Is there any particular reason you don’t want have ssh inside the container at least initially? You can always disable it after you’re done with initial configuration.

kind regards  
Pshem

---

<div class="post-metadata">

**Author:** ![Mario\_Keller](https://avatars.discourse-cdn.com/v4/letter/m/90ced4/32.png) [@Mario\_Keller](https://forum.ansible.com/u/Mario_Keller)\
**Post date:** [January 25, 2017, 7:25am UTC](https://forum.ansible.com/t/remote-access-to-lxc-containers-on-lxc-host-without-ssh-inside-the-containers/23546/4 "2017-01-25T07:25:44Z")

</div>

Running a bunch of sshd on a single host in every container just for automation is the opposite to the lightweight idea of ansible. Currently the host has lxc installed, so the lxd connection will not work because it uses “lxc exec” instead of “lxc-attach” to run commands.  
I will give lxd a try on a new host to check if this will solve my problem at least for new lxd(c) hosts.

---

<div class="post-metadata">

**Author:** ![Johannes\_Kastl](https://avatars.discourse-cdn.com/v4/letter/j/bbe5ce/32.png) [@Johannes\_Kastl](https://forum.ansible.com/u/Johannes_Kastl)\
**Post date:** [January 25, 2017, 7:34am UTC](https://forum.ansible.com/t/remote-access-to-lxc-containers-on-lxc-host-without-ssh-inside-the-containers/23546/5 "2017-01-25T07:34:28Z")

</div>

+1 for installing ssh in the container.

And use the host as a jumphost (ProxyCommand in ~/.ssh/config).

Johannes

---

<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, 5:14pm UTC](https://forum.ansible.com/t/remote-access-to-lxc-containers-on-lxc-host-without-ssh-inside-the-containers/23546/6 "2017-01-25T17:14:07Z")

</div>

It is, furthermore, illogical and causes a chicken-egg-problem:

How would one install an sshd with ansible, if ansible requires an sshd to be present?

---

<div class="post-metadata">

**Author:** ![Johannes\_Kastl](https://avatars.discourse-cdn.com/v4/letter/j/bbe5ce/32.png) [@Johannes\_Kastl](https://forum.ansible.com/u/Johannes_Kastl)\
**Post date:** [January 25, 2017, 6:19pm UTC](https://forum.ansible.com/t/remote-access-to-lxc-containers-on-lxc-host-without-ssh-inside-the-containers/23546/7 "2017-01-25T18:19:24Z")

</div>

> It is, furthermore, illogical and causes a chicken-egg-problem:

Depends on what you define as 'containers'.

I have multiple containers running on my hosts, and all have sshd  
running. Thus I can manage them like normal machines. No matter if  
this is a VM or a container or a real machine. The same things apply.

But of course, your mileage my vary.

> How would one install an sshd with ansible, if ansible requires an  
> sshd to be present?

Exactly as you would create the container, by starting the task from  
the host. As this is a one time thing I do not consider this a major  
problem. Idempotency is slightly harder, but solvable.

Johannes

---

<div class="post-metadata">

**Author:** ![Pshem\_Kowalczyk](https://avatars.discourse-cdn.com/v4/letter/p/e480ec/32.png) [@Pshem\_Kowalczyk](https://forum.ansible.com/u/Pshem_Kowalczyk)\
**Post date:** [January 25, 2017, 6:29pm UTC](https://forum.ansible.com/t/remote-access-to-lxc-containers-on-lxc-host-without-ssh-inside-the-containers/23546/8 "2017-01-25T18:29:15Z")

</div>

One could argue that if you run lxc/lxd you’re after system-like functionality (and not docker-style containers) hence you treat it the same way you’d treat a VM.

One easy way of installing ssh inside a container is to use images with cloud-init.

kind regards  
Pshem
