# Python script using different ssh port

**URL:** <https://forum.ansible.com/t/python-script-using-different-ssh-port/21865>\
**Category:** Ansible Project\
**Created:** [June 27, 2016, 1:30pm UTC](https://forum.ansible.com/t/python-script-using-different-ssh-port/21865 "2016-06-27T13:30:24Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Idan\_null](https://avatars.discourse-cdn.com/v4/letter/i/eb9ed0/32.png) [@Idan\_null](https://forum.ansible.com/u/Idan_null)\
**Post date:** [June 27, 2016, 1:30pm UTC](https://forum.ansible.com/t/python-script-using-different-ssh-port/21865/1 "2016-06-27T13:30:24Z")

</div>

Hello everyone,  
I’m using the Ansible 2 module in Python to connect to a host with different port (not 22)  
The script I’m using is:  
[https://github.com/ansible/ansible/blob/devel/examples/scripts/uptime.py](https://github.com/ansible/ansible/blob/devel/examples/scripts/uptime.py)

But my ssh port in the host i’m trying to connect to is 2222,  
so I changed it to this:

def main():  
**host\_list = [‘10.0.0.10’]**  
Options = namedtuple(‘Options’, [‘connection’,‘module\_path’, ‘forks’, ‘remote\_user’,  
‘private\_key\_file’, ‘ssh\_common\_args’, ‘ssh\_extra\_args’, ‘sftp\_extra\_args’,  
‘scp\_extra\_args’, ‘become’, ‘become\_method’, ‘become\_user’, ‘verbosity’, ‘check’])

# initialize needed objects

variable\_manager = VariableManager()  
loader = DataLoader()  
options = Options(connection=‘smart’, module\_path=‘/usr/share/ansible’, forks=100,  
remote\_user=‘user’, private\_key\_file=None, ssh\_common\_args=None, ssh\_extra\_args=None,  
**sftp\_extra\_args='-P 2222 '** , scp\_extra\_args=None, become=None, become\_method=None,  
become\_user=None, verbosity=None, check=False)

But i’m getting a error:

DOWN \*\*\*\*\*\*\*\*\*  
10.0.0.10 \>\>\> Failed to connect to the host via ssh.

Any ideas?  
Thank you
