Score:0

Ansible SSH From A -> B -> C using SSH Config on B

gp flag

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?

Nikita Kipriyanov avatar
za flag
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.
mickadoo avatar
gp flag
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)
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.