SSH Error: data could not be sent (how to change port?)

When running the command to deploy, I cannot connect via SSH to the server. I guess it’s because Ansible is probably using a default port of 22, however, knowing that it should be fairly simple to change the port and run the command in my terminal. I found a similar topic on this forum on how to change the port in hosts/production, so I did as follow :

[production]
my_server_ip_here ansible_port=33654

[web]
my_server_ip_here ansible_port=33654 

This didn’t change anything. In fact, even in my error it doesn’t say I’m trying to connect to the server with the port of 33654, it says the exact same thing as before. I am guessing that Ansible is not taking my port number in consideration.

My ansible version is 2.4.3.0, any help would be greatly appreciated!

You say “deploy” but did the connection work in the prior step of provisioning? (see Trellis usage of terms provision vs deploy). If you’re trying to run deploy.yml before server.yml, connection will fail because the web_user used with deploy.yml will not yet be set up.

I see the port in the output only when I use -vvv:

# provision
$ ansible-playbook server.yml -e env=production -vvv


# deploy
$ ansible-playbook deploy.yml -e env=production -e site=example.com -vvv

If regular port 22, I see this in the output:

"SSH_CONNECTION": "24.11.94.102 52768 159.203.12.129 22"

where 159.203.12.129 is the remote host and 22 is the port.

If I change to ansible_port=33654, I see this in the output all over the place:

Port=33654

I don’t know why the ansible_port variable wouldn’t work, but here’s an alternative:

[production]
159.203.12.129:33654

[web]
159.203.12.129:33654

More alternatives for setting port:

  • remote_port in your ansible.cfg.
  • add -o Port=33654 to ssh_args
  • add port to an entry for the host in local machine ~/.ssh/config
  • specify --ssh-extra-args (with port) with ansible-playbook command
1 Like