# Need help in adding ssh\_port dynamically

**URL:** <https://forum.ansible.com/t/need-help-in-adding-ssh-port-dynamically/34777>\
**Category:** AWX Project\
**Created:** [March 13, 2021, 4:15pm UTC](https://forum.ansible.com/t/need-help-in-adding-ssh-port-dynamically/34777 "2021-03-13T16:15:59Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kumaresan\_M](https://avatars.discourse-cdn.com/v4/letter/k/e19b73/32.png) [@Kumaresan\_M](https://forum.ansible.com/u/Kumaresan_M)\
**Post date:** [March 13, 2021, 4:15pm UTC](https://forum.ansible.com/t/need-help-in-adding-ssh-port-dynamically/34777/1 "2021-03-13T16:15:59Z")

</div>

Hi All,

The dynamic inventory has been implemented with servicenow collections however few servers we are using custom ssh\_port rest all servers uses default port 22.Since it’s dynamic inventory is there way to add ssh\_port dynamically.

Regards  
Kumar

---

<div class="post-metadata">

**Author:** ![ffirg](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/ffirg/32/10029_2.png) [@ffirg](https://forum.ansible.com/u/ffirg)\
**Post date:** [March 15, 2021, 9:36pm UTC](https://forum.ansible.com/t/need-help-in-adding-ssh-port-dynamically/34777/2 "2021-03-15T21:36:23Z")

</div>

Can you not setup a custom port field in the SNOW CMDB and use the fields filter from the [https://github.com/ServiceNowITOM/servicenow-ansible/blob/deveål/plugins/inventory/now.py](https://github.com/ServiceNowITOM/servicenow-ansible/blob/deve%C3%A5l/plugins/inventory/now.py) to retrieve it as a hostvar?

---

<div class="post-metadata">

**Author:** ![Kumaresan\_M](https://avatars.discourse-cdn.com/v4/letter/k/e19b73/32.png) [@Kumaresan\_M](https://forum.ansible.com/u/Kumaresan_M)\
**Post date:** [March 16, 2021, 5:09pm UTC](https://forum.ansible.com/t/need-help-in-adding-ssh-port-dynamically/34777/3 "2021-03-16T17:09:51Z")

</div>

Hi Phil,

Since we have thousand of servers and have only few servers uses different ssh port not sure adding custom filed need to be done for all the servers or is there way to add only few servers in servicenow as all the servers part of same CMDB table in servicenow.Is there any other options to achieve dynamic ssh\_port change? May be defining ansible\_hostname: test1 ansible\_port: 2444 something like this at group level variables for specific host will help in tower?

Regards  
Kumar

---

<div class="post-metadata">

**Author:** ![ffirg](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/ffirg/32/10029_2.png) [@ffirg](https://forum.ansible.com/u/ffirg)\
**Post date:** [March 17, 2021, 9:28am UTC](https://forum.ansible.com/t/need-help-in-adding-ssh-port-dynamically/34777/4 "2021-03-17T09:28:47Z")

</div>

If you only have a few then hostvars/groupvars setting for ansible\_ssh\_port for those would be my way to go.  
Otherwise that custom field in the CMDB could provide ansible\_ssh\_port. If not set for a host then groupvars/all or similar could have a default set.
