# ec2.py as inventory script and custom SSH port

**URL:** <https://forum.ansible.com/t/ec2-py-as-inventory-script-and-custom-ssh-port/12746>\
**Category:** Ansible Project\
**Tags:** ansible-project\
**Created:** [May 1, 2013, 11:25am UTC](https://forum.ansible.com/t/ec2-py-as-inventory-script-and-custom-ssh-port/12746 "2013-05-01T11:25:13Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [May 1, 2013, 11:25am UTC](https://forum.ansible.com/t/ec2-py-as-inventory-script-and-custom-ssh-port/12746/1 "2013-05-01T11:25:13Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Bikash\_B](https://avatars.discourse-cdn.com/v4/letter/b/6f9a4e/32.png) [@Bikash\_B](https://forum.ansible.com/u/Bikash_B)\
**Post date:** [May 2, 2013, 3:29pm UTC](https://forum.ansible.com/t/ec2-py-as-inventory-script-and-custom-ssh-port/12746/2 "2013-05-02T15:29:51Z")

</div>

Thanks for replying.

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

Thanks,  
Kaji

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [May 2, 2013, 4:18pm UTC](https://forum.ansible.com/t/ec2-py-as-inventory-script-and-custom-ssh-port/12746/3 "2013-05-02T16:18:41Z")

</div>

“or from shell export of ansible\_ssh\_args to 1234”

That’s not a way to set this.
