Skip to content

Commit

Permalink
Allow override of ssh/sftp port for init subcommand
Browse files Browse the repository at this point in the history
  • Loading branch information
Tejeda, Engelbert committed Oct 11, 2019
1 parent 99f8505 commit 578ac2a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
11 changes: 7 additions & 4 deletions ansible_taskrunner/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,19 +295,22 @@ def init(**kwargs):
if is_windows:
bastion_remote_path = kwargs.get('bastion_remote_path')
bastion_host = kwargs['bastion_host']
bastion_user = kwargs.get('bastion_user')
bastion_host_port = kwargs.get('bastion_host_port') or '22'
bastion_user = kwargs.get('bastion_user') or local_username
bastion_ssh_key_file = kwargs.get('bastion_ssh_key_file')
if not bastion_user:
bastion_user = local_username
if not bastion_remote_path:
cur_dir = os.path.basename(os.getcwd())
bastion_remote_path = '/home/{}/{}'.format(bastion_user, cur_dir)
bastion_remote_path = '/home/{}/ansible-taskrunner/{}'.format(bastion_user, cur_dir)
if not bastion_ssh_key_file:
home_dir = os.path.expanduser('~')
bastion_ssh_key_file = os.path.join(home_dir, '.ssh', 'id_rsa')
if not os.path.exists(bastion_ssh_key_file):
logger.error("SSH key '%s' not found, specify/generate a new/different key" % bastion_ssh_key_file)
sys.exit(1)
settings_vars = {
'bastion_remote_path': bastion_remote_path,
'bastion_host': bastion_host,
'bastion_host_port': bastion_host_port,
'bastion_user': bastion_user,
'bastion_ssh_key_file': bastion_ssh_key_file.replace('\\', '\\\\')
}
Expand Down
5 changes: 4 additions & 1 deletion ansible_taskrunner/libs/click_extras/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,13 +241,16 @@ def bastion_mode(self, func):
help='Specify host (bastion mode settings file)',
required=True)
func = option(func)
option = click.option('--bastion-host-port', '-p',
help='Specify host port (bastion mode settings file)')
func = option(func)
option = click.option('--bastion-user', '-u',
help='Override username (bastion mode settings file)')
func = option(func)
option = click.option('--bastion-remote-path', '-r',
help='Specify remote workspace (bastion mode settings file)')
func = option(func)
option = click.option('--bastion-ssh-key-file', '-s',
option = click.option('--bastion-ssh-key-file', '-k',
help='Override ssh key file (bastion mode settings file)')
func = option(func)
return func
Expand Down
2 changes: 1 addition & 1 deletion ansible_taskrunner/libs/help/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"host": "$bastion_host",
"user": "$bastion_user",
"ssh_key_file": "$bastion_ssh_key_file",
"port": "22",
"port": "$bastion_host_port",
"remote_path": "$bastion_remote_path",
"ignore_regexes": [
"\\\\.sublime-(project|workspace)", "sftp-config(-alt\\\\d?)?\\\\.json",
Expand Down

0 comments on commit 578ac2a

Please sign in to comment.