Fixes #5109 synchronize module ssh port
Added a parameter for dest_port and also check ansible_ssh_port inventory variable.
This commit is contained in:
parent
c259993559
commit
d227614529
2 changed files with 20 additions and 1 deletions
|
@ -70,6 +70,12 @@ class ActionModule(object):
|
|||
src_host = '127.0.0.1'
|
||||
dest_host = inject.get('ansible_ssh_host', inject['inventory_hostname'])
|
||||
|
||||
dest_port = options.get('dest_port')
|
||||
inv_port = inject.get('ansible_ssh_port', inject['inventory_hostname'])
|
||||
if inv_port != dest_port and inv_port != inject['inventory_hostname']:
|
||||
options['dest_port'] = inv_port
|
||||
|
||||
|
||||
# edge case: explicit delegate and dest_host are the same
|
||||
if dest_host == inject['delegate_to']:
|
||||
dest_host = '127.0.0.1'
|
||||
|
|
|
@ -34,6 +34,11 @@ options:
|
|||
description:
|
||||
- Path on the destination machine that will be synchronized from the source; The path can be absolute or relative.
|
||||
required: true
|
||||
dest_port:
|
||||
description:
|
||||
- Port number for ssh on the destination host. The ansible_ssh_port inventory var takes precedence over this value.
|
||||
default: 22
|
||||
version_added: "1.5"
|
||||
mode:
|
||||
description:
|
||||
- Specify the direction of the synchroniztion. In push mode the localhost or delgate is the source; In pull mode the remote host in context is the source.
|
||||
|
@ -150,6 +155,7 @@ def main():
|
|||
argument_spec = dict(
|
||||
src = dict(required=True),
|
||||
dest = dict(required=True),
|
||||
dest_port = dict(default=22),
|
||||
delete = dict(default='no', type='bool'),
|
||||
private_key = dict(default=None),
|
||||
rsync_path = dict(default=None),
|
||||
|
@ -168,6 +174,7 @@ def main():
|
|||
|
||||
source = module.params['src']
|
||||
dest = module.params['dest']
|
||||
dest_port = module.params['dest_port']
|
||||
delete = module.params['delete']
|
||||
private_key = module.params['private_key']
|
||||
rsync_path = module.params['rsync_path']
|
||||
|
@ -221,8 +228,14 @@ def main():
|
|||
private_key = ''
|
||||
else:
|
||||
private_key = '-i '+ private_key
|
||||
cmd = cmd + " --rsh '%s %s -o %s'" % ('ssh', private_key,
|
||||
|
||||
if dest_port != 22:
|
||||
cmd += " --rsh '%s %s -o %s -o Port=%s'" % ('ssh', private_key,
|
||||
'StrictHostKeyChecking=no', dest_port)
|
||||
else:
|
||||
cmd += " --rsh '%s %s -o %s'" % ('ssh', private_key,
|
||||
'StrictHostKeyChecking=no') # need ssh param
|
||||
|
||||
if rsync_path:
|
||||
cmd = cmd + " --rsync-path '%s'" %(rsync_path)
|
||||
changed_marker = '<<CHANGED>>'
|
||||
|
|
Loading…
Reference in a new issue