1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

Add port arg to establish ssh connection in nxos_file_copy (#33304)

* Add port arg to establish ssh connection in nxos_file_copy

Signed-off-by: Trishna Guha <trishnaguha17@gmail.com>

* resolve kedar's comment
This commit is contained in:
Trishna Guha 2017-11-28 10:54:23 +05:30 committed by Kedar K
parent a18b7d9b01
commit 819f9ee8fa
3 changed files with 15 additions and 1 deletions

View file

@ -56,6 +56,12 @@ options:
their default values. their default values.
required: false required: false
default: null default: null
connect_ssh_port:
description:
- SSH port to connect to server during transfer of file
required: false
default: 22
version_added: "2.5"
''' '''
EXAMPLES = ''' EXAMPLES = '''
@ -63,6 +69,7 @@ EXAMPLES = '''
local_file: "./test_file.txt" local_file: "./test_file.txt"
remote_file: "test_file.txt" remote_file: "test_file.txt"
provider: "{{ cli }}" provider: "{{ cli }}"
connect_ssh_port: "{{ ansible_ssh_port }}"
''' '''
RETURN = ''' RETURN = '''
@ -148,13 +155,15 @@ def transfer_file(module, dest):
hostname = module.params.get('host') or provider.get('host') hostname = module.params.get('host') or provider.get('host')
username = module.params.get('username') or provider.get('username') username = module.params.get('username') or provider.get('username')
password = module.params.get('password') or provider.get('password') password = module.params.get('password') or provider.get('password')
port = module.params.get('connect_ssh_port')
ssh = paramiko.SSHClient() ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect( ssh.connect(
hostname=hostname, hostname=hostname,
username=username, username=username,
password=password) password=password,
port=port)
full_remote_path = '{}{}'.format(module.params['file_system'], dest) full_remote_path = '{}{}'.format(module.params['file_system'], dest)
scp = SCPClient(ssh.get_transport()) scp = SCPClient(ssh.get_transport())
@ -181,6 +190,7 @@ def main():
local_file=dict(required=True), local_file=dict(required=True),
remote_file=dict(required=False), remote_file=dict(required=False),
file_system=dict(required=False, default='bootflash:'), file_system=dict(required=False, default='bootflash:'),
connect_ssh_port=dict(required=False, type='int', default=22),
) )
argument_spec.update(nxos_argument_spec) argument_spec.update(nxos_argument_spec)

View file

@ -24,6 +24,7 @@
username: "{{ ansible_ssh_user }}" username: "{{ ansible_ssh_user }}"
password: "{{ ansible_ssh_pass }}" password: "{{ ansible_ssh_pass }}"
host: "{{ ansible_host }}" host: "{{ ansible_host }}"
connect_ssh_port: "{{ ansible_ssh_port }}"
register: result register: result
- assert: &true - assert: &true
@ -51,6 +52,7 @@
username: "{{ ansible_ssh_user }}" username: "{{ ansible_ssh_user }}"
password: "{{ ansible_ssh_pass }}" password: "{{ ansible_ssh_pass }}"
host: "{{ ansible_host }}" host: "{{ ansible_host }}"
connect_ssh_port: "{{ ansible_ssh_port }}"
register: result register: result
- assert: *true - assert: *true

View file

@ -26,6 +26,7 @@
username: "{{ ansible_ssh_user }}" username: "{{ ansible_ssh_user }}"
password: "{{ ansible_ssh_pass }}" password: "{{ ansible_ssh_pass }}"
host: "{{ ansible_host }}" host: "{{ ansible_host }}"
connect_ssh_port: "{{ ansible_ssh_port }}"
register: result register: result
- assert: &true - assert: &true
@ -54,6 +55,7 @@
username: "{{ ansible_ssh_user }}" username: "{{ ansible_ssh_user }}"
password: "{{ ansible_ssh_pass }}" password: "{{ ansible_ssh_pass }}"
host: "{{ ansible_host }}" host: "{{ ansible_host }}"
connect_ssh_port: "{{ ansible_ssh_port }}"
register: result register: result
- assert: *true - assert: *true