summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrian Coca <bcoca@users.noreply.github.com>2022-01-10 12:29:35 -0500
committerGitHub <noreply@github.com>2022-01-10 12:29:35 -0500
commitaa022dba2d141cbd3b862767400ba4f714a9edd1 (patch)
tree9a4c2091a27c70413f0cf5cfb26b9f86dcaa5e45
parent0ef5274a3c6189e8fa6a7d97993c165ab548fe95 (diff)
downloadansible-aa022dba2d141cbd3b862767400ba4f714a9edd1.tar.gz
ssh connection, handle 'fun' control paths (#76424)
* handle 'fun' control paths by quoting the option when passed to ssh cli Co-authored-by: Matt Clay <matt@mystile.com>
-rw-r--r--changelogs/fragments/ssh_quote_cp.yml2
-rw-r--r--lib/ansible/plugins/connection/ssh.py3
-rwxr-xr-xtest/integration/targets/connection_ssh/runme.sh4
3 files changed, 7 insertions, 2 deletions
diff --git a/changelogs/fragments/ssh_quote_cp.yml b/changelogs/fragments/ssh_quote_cp.yml
new file mode 100644
index 0000000000..eef867606e
--- /dev/null
+++ b/changelogs/fragments/ssh_quote_cp.yml
@@ -0,0 +1,2 @@
+bugfixes:
+ - ssh connection - properly quote controlpersist path given by user to avoid issues with spaces and other characters
diff --git a/lib/ansible/plugins/connection/ssh.py b/lib/ansible/plugins/connection/ssh.py
index f6c0ba2027..f888a7d971 100644
--- a/lib/ansible/plugins/connection/ssh.py
+++ b/lib/ansible/plugins/connection/ssh.py
@@ -363,7 +363,6 @@ import subprocess
import time
from functools import wraps
-from ansible import constants as C
from ansible.errors import (
AnsibleAuthenticationFailure,
AnsibleConnectionFailure,
@@ -777,7 +776,7 @@ class Connection(ConnectionBase):
self.port,
self.user
)
- b_args = (b"-o", b"ControlPath=" + to_bytes(self.control_path % dict(directory=cpdir), errors='surrogate_or_strict'))
+ b_args = (b"-o", b'ControlPath="%s"' % to_bytes(self.control_path % dict(directory=cpdir), errors='surrogate_or_strict'))
self._add_args(b_command, b_args, u"found only ControlPersist; added ControlPath")
# Finally, we add any caller-supplied extras.
diff --git a/test/integration/targets/connection_ssh/runme.sh b/test/integration/targets/connection_ssh/runme.sh
index cbadf1d5d1..4d4302637d 100755
--- a/test/integration/targets/connection_ssh/runme.sh
+++ b/test/integration/targets/connection_ssh/runme.sh
@@ -71,3 +71,7 @@ ansible-playbook check_ssh_defaults.yml "$@" -i test_connection.inventory
# ensure we can load from ini cfg
ANSIBLE_CONFIG=./test_ssh_defaults.cfg ansible-playbook verify_config.yml "$@"
+
+# ensure we handle cp with spaces correctly, otherwise would fail with
+# `"Failed to connect to the host via ssh: command-line line 0: keyword controlpath extra arguments at end of line"`
+ANSIBLE_SSH_CONTROL_PATH='/tmp/ssh cp with spaces' ansible -m ping all -e ansible_connection=ssh -i test_connection.inventory "$@"