# Changing ssh port with Ansible

**URL:** <https://forum.ansible.com/t/changing-ssh-port-with-ansible/12080>\
**Category:** Ansible Project\
**Tags:** ansible-project\
**Created:** [November 12, 2012, 3:56pm UTC](https://forum.ansible.com/t/changing-ssh-port-with-ansible/12080 "2012-11-12T15:56:32Z")\
**Posts on this page:** 2\
**Page:** 2

<div class="post-metadata">

**Author:** ![Michael\_DeHaan](https://avatars.discourse-cdn.com/v4/letter/m/c4cdca/32.png) [@Michael\_DeHaan](https://forum.ansible.com/u/Michael_DeHaan)\
**Post date:** [November 29, 2012, 9:11pm UTC](https://forum.ansible.com/t/changing-ssh-port-with-ansible/12080/21 "2012-11-29T21:11:57Z")

</div>

It depends on what version you are using where the extra\_vars priority is.

However, the only intent of this variable is set in the inventory  
file, you shouldn't need or want to override it elsewhere.

---

<div class="post-metadata">

**Author:** ![Ahmad\_Khayyat](https://avatars.discourse-cdn.com/v4/letter/a/858c86/32.png) [@Ahmad\_Khayyat](https://forum.ansible.com/u/Ahmad_Khayyat)\
**Post date:** [November 29, 2012, 9:18pm UTC](https://forum.ansible.com/t/changing-ssh-port-with-ansible/12080/22 "2012-11-29T21:18:09Z")

</div>

Here is how it is working for me, using a recent ansible checkout:

I set every host's default ssh port in the inventory on the host line as  
follows:  
server1:2222

Then, I override it on the command line using '-e ansible\_ssh\_port=22'

[Previous page](https://forum.ansible.com/t/changing-ssh-port-with-ansible/12080.md?page=1)
