When port forwarding a remote SSH server to a local port and using that local port in Ansible, synchronize module wrongfully treats it as a local connection and does not perform the transfer over SSH connection.
Running Ubuntu 22.04 on both the controller node and the remote.
STEPS TO REPRODUCE
In real environment, I forward the SSH port of a different machine in the network that the machine I ssh into is but this example should highlight the issue as well and is simple to create a reproduction for.
Create a file playbook.yaml with the following contents:
SUMMARY
When port forwarding a remote SSH server to a local port and using that local port in Ansible,
synchronize
module wrongfully treats it as a local connection and does not perform the transfer over SSH connection.ISSUE TYPE
COMPONENT NAME
synchronize
ANSIBLE VERSION
COLLECTION VERSION
CONFIGURATION
OS / ENVIRONMENT
Running Ubuntu 22.04 on both the controller node and the remote.
STEPS TO REPRODUCE
In real environment, I forward the SSH port of a different machine in the network that the machine I ssh into is but this example should highlight the issue as well and is simple to create a reproduction for.
playbook.yaml
with the following contents:inventory.yaml
with the following contents (replace<user>
with the user to connect with):folder
.file
in thefolder
folder.ssh <user>@<host> -L 127.0.0.1:1234:127.0.0.1:22
in another terminal window.ansible-playbook playbook.yaml -i inventory.yaml
./tmp/folder
was created on the controller node rather than the remote node.For comparison to how it should actually work, you can change the
inventory.yaml
file to:EXPECTED RESULTS
I expected the local folder to get properly synced to the remote folder.
ACTUAL RESULTS
The local folder gets synced to the local folder.
Here's the actual output: https://gist.github.com/Jackenmen/20de4a647cfb607f5a7d17232a01a998/raw/c57f02ec315fcf678db67a7034c5b7a9b751deb2/actual_result_1234.log
and for comparison, here's the expected output that I get when using
<user>@<host>:22
directly: https://gist.github.com/Jackenmen/20de4a647cfb607f5a7d17232a01a998/raw/c57f02ec315fcf678db67a7034c5b7a9b751deb2/expected_result.log