From 728970232e13fa36dfaa4b91a55d6b152eb9cd83 Mon Sep 17 00:00:00 2001 From: Matt Martz Date: Thu, 7 Mar 2019 11:47:33 -0600 Subject: [PATCH] Properly quote the username to support usernames with spaces (#53420) --- changelogs/fragments/ssh-quote-user.yaml | 2 ++ lib/ansible/plugins/connection/ssh.py | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) create mode 100644 changelogs/fragments/ssh-quote-user.yaml diff --git a/changelogs/fragments/ssh-quote-user.yaml b/changelogs/fragments/ssh-quote-user.yaml new file mode 100644 index 0000000000..1ccf5fa939 --- /dev/null +++ b/changelogs/fragments/ssh-quote-user.yaml @@ -0,0 +1,2 @@ +bugfixes: +- ssh - Properly quote the username to allow usernames containing spaces (https://github.com/ansible/ansible/issues/49968) diff --git a/lib/ansible/plugins/connection/ssh.py b/lib/ansible/plugins/connection/ssh.py index 724f48c07b..de96c3869a 100644 --- a/lib/ansible/plugins/connection/ssh.py +++ b/lib/ansible/plugins/connection/ssh.py @@ -612,7 +612,7 @@ class Connection(ConnectionBase): if user: self._add_args( b_command, - (b"-o", b"User=" + to_bytes(self._play_context.remote_user, errors='surrogate_or_strict')), + (b"-o", b'User="%s"' % to_bytes(self._play_context.remote_user, errors='surrogate_or_strict')), u"ANSIBLE_REMOTE_USER/remote_user/ansible_user/user/-u set" )