the variable ANSIBLE_SSH_PORT only sets the default and is a bit of a legacy way to set things anyway.
You want to set the following in an inventory variable:
ansible_ssh_port
If you are using the ec2 inventory script you can still put variables in host_vars or group_vars/ directories.
“Stopped working” doesn’t tell us much, but when you say it stopped working when you changed the port, it seems to imply you had some hosts on 22 still.
This is why “ansible_ssh_port” is settable on a per host or group basis.
What i meant with stopped working is that it was working with default port 22. As soon as i changed the default port to say 1234 for ssh in the target machine, ansible won’t run successfully even when i set the ansible_ssh_port in ec2.ini file or from shell export of ansible_ssh_args to 1234. I was just experimenting with few stuffs like in example
ansible all -m ping -u ubuntu
Above example works when the target ec2 instances have ssh daemon running in 22 port but after changing the default port to 1234, it would not run successfully even if i set ansible_ssh_port in ec2.ini or shell export in ansible_ssh_args