connection_type lxd and remote machine?

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 :slight_smile:

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/

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.

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’.

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