SFTP fails with '[user@server]' when transferring templates

I just ran across the Github issue https://github.com/ansible/ansible/issues/16066 which is unfortunately closed.

In short, SFTP of templates and files by Ansible places quoted square bracket around the hostname ‘[…]’. If this is a plain host name, there is no issue. But if there is a username@ on the front of the hostname, then SFTP fails to connect, since it treats the whole character string when trying to resolve the host.

In my case the username is necessary, since I have to segregate certain hosts this way in order to have hostname:port to be treated as independent hosts (which Ansible sees otherwise as an identical host, incorrectly in my opinion, but that is a different story).

I run ansible-playbook with -vvvv and find the SFTP failure. When running the reported command in the terminal it fails in the same way as Ansible:

sftp -b - -vvv -o StrictHostKeyChecking=no -o Port=2222 -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=vagrant -o ConnectTimeout=10 '[vagrant@vagrant-fphs-webapp-box]

It is true that removing the vagrant@ from within the ‘’ allows an SFTP connection from the command line, but this is infeasible for me within Ansible for the reasons stated.

Since the Github issues is closed I can either create a new one, or maybe we could have a discussion here to see what a team member’s thoughts are on resolving this issue.