Skip to content

Commit

Permalink
Added cli option for overriding ssh key file
Browse files Browse the repository at this point in the history
  • Loading branch information
Tejeda, Engelbert committed Oct 1, 2019
1 parent e4600a7 commit 86a0d45
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 7 deletions.
18 changes: 15 additions & 3 deletions ansible_taskrunner/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# Import builtins
from __future__ import print_function
from collections import OrderedDict
import getpass
import logging
import logging.handlers
import os
Expand Down Expand Up @@ -93,6 +94,7 @@
sftp_config_file = 'sftp-config.json'
superconf = SuperDuperConfig(__program_name__)
config = superconf.load_config(config_file)
local_username = getpass.getuser()

# We'll pass this down to the run invocation
global exe_path
Expand Down Expand Up @@ -236,8 +238,19 @@ def cli(**kwargs):
logger.debug('Debug Mode Enabled, keeping any generated temp files')
return 0

init_epilog = ''
if is_windows:
init_epilog = '''
Examples:
- Initialize an empty workspace
tasks init
- Initialize an empty workspace config with username and remote path
tasks init -h myhost.example.org -u {0} -r "/home/{0}/git/ansible"
'''.format(local_username)

# Init command
@cli.command(help='Initialize local directory with sample files')
@cli.command(cls=ExtendedHelp, help='Initialize local directory with sample files',
epilog=init_epilog, context_settings=dict(max_content_width=180))
@click.version_option(version=__version__)
@click.option('--show-samples', '-m', is_flag=True,
help='Only show a sample task manifest, don\'t write it')
Expand Down Expand Up @@ -275,8 +288,7 @@ def init(**kwargs):
bastion_user = kwargs.get('bastion_user')
bastion_ssh_key_file = kwargs.get('bastion_ssh_key_file')
if not bastion_user:
import getpass
bastion_user = getpass.getuser()
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)
Expand Down
9 changes: 6 additions & 3 deletions ansible_taskrunner/lib/click_extras/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,14 +218,17 @@ def process_options(self, parameters, func, is_required=False):
def bastion_mode(self, func):
if sys.platform in ['win32', 'cygwin']:
option = click.option('--bastion-host', '-h',
help='Specify host for bastion mode',
help='Specify host (bastion mode settings file)',
required=True)
func = option(func)
option = click.option('--bastion-user', '-u',
help='Specify username for initializing bastion mode settings file')
help='Override username (bastion mode settings file)')
func = option(func)
option = click.option('--bastion-remote-path', '-r',
help='Specify remote workspace for bastion mode')
help='Specify remote workspace (bastion mode settings file)')
func = option(func)
option = click.option('--bastion-ssh-key-file', '-s',
help='Override ssh key file (bastion mode settings file)')
func = option(func)
return func

Expand Down
2 changes: 1 addition & 1 deletion ansible_taskrunner/lib/providers/ansible.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def invoke_bastion_mode(self, bastion_settings, invocation):
)
sys.exit(1)
else:
logger.error("Could not find %s, please run 'tasks init'" % bastion.config_file)
logger.error("Could not find %s, please run 'tasks init --help'" % bastion.config_file)
sys.exit(1)
# Import third-party and custom modules
try:
Expand Down

0 comments on commit 86a0d45

Please sign in to comment.