0

There is a very similar question to what I'm asking at SSH from A through B to C, using private key on B

That question does have a solution that works for me, which is

ssh -t B ssh C

However I've failed to convert this to something usable by Ansible. When I try it complains about invalid syntax. This is what I tried

ansible_ssh_common_args='-t -i ~/.ssh/mykey admin@B ssh'

Which gives me "syntax error near unexpected token". I could persist with this, but I get the impression that Ansible might have some more serious issues with hijacking the SSH command like this.

I've also asked a similar question on StackOverflow with https://stackoverflow.com/q/73975618/1196369 - but without success.

I have managed to get the connection working using the -J B (ProxyJump) or ProxyCommand options, however both of these seem to skip the SSH configuration on B. I've added configuration to ~/.ssh/config on B so that it will use a reverse tunnel when connecting to C. Using ssh -t B ssh C picks up this config and the reverse tunnel is created, but using ProxyJump or ProxyCommand does not create the reverse tunnel.

If the reverse tunnel is not created then C cannot access the internet, and this is required for the Ansible playbook I'd like to run.

I can combine -R for the reverse tunnel in the original command, and that works... but it means the tunnel is created from C -> A -> B and not C -> B as I would like. This looks something like:

ansible_ssh_common_args='-J admin@B'
ansible_ssh_extra_args='-R 3129:B:3128'

So my main question is how can I use ProxyJump (-J) in combination with RemoteForward (-R) on Ansible where the reverse tunnel is created from the proxy server, and not the host?

mickadoo
  • 101
  • 2
  • 2
    When using jumphost you don't need a config on B. All the configuration belongs to A, the node where Ansbile is running. Only public keys need to be distributed. – Nikita Kipriyanov Oct 07 '22 at 10:12
  • Hi Nikita, yeah - jumphost works fine on it's own, but I'd like to use a reverse tunnel when connecting from B -> C and I'm not sure how I can do this (except when I manually SSH into B, then use `-R` to ssh to C) – mickadoo Oct 07 '22 at 10:17

0 Answers0