Chaining connection plugins

Is it possible to chain multiple connection plugins together. Specifically, I would want ansible to:

  • Connect to my jail host with ssh
  • Use the jail connection plugin to attach to a jail

Following an example intended for lxc, I set ansible_host to the form host:jail. However, I just get a message saying “jail connection requires running as root”. Passing -kuroot, it will prompt for an SSH password. Is this not working an error on my part, an ansible limitation or perhaps a bug/limitation in the jail connection plugin.

You can run Ansible using Ansible – I have done this for servers with chroots and the chroot connection plugin, I probably haven’t documented it very well but you could look at this chroot role.

1 Like

Connection plugins don’t stack, but you can create an ssh+jail plugin that does both (I believe someone did already), also see lxc/lxd connection plugins.

1 Like

I found something along those lines at GitHub - austinhyde/ansible-sshjail: An Ansible connection plugin for provisioning FreeBSD jails remotely
The README talking about Python 2.7 was initially a bit concerning but it appears to exist in FreeBSD ports and does work well. The example they give of using add_host to add add the jail to the inventory also worked well for my use case along with import_playbook.

The other suggestion of running ansible from ansible is interesting and I could see that working in other circumstances but my FreeBSD host systems are very minimal and wouldn’t typically contain a checkout of the playbooks which would be needed.

1 Like

also look at ansible-pull or create your
own playbook that does a git checkout of your plays to execute.