Skip to content

Commit

Permalink
Adjusted bastion mode sync logic to quit if we fail to create remote dir
Browse files Browse the repository at this point in the history
  • Loading branch information
Tejeda, Engelbert committed Oct 1, 2019
1 parent da50945 commit 0084ce5
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions ansible_taskrunner/lib/providers/ansible.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,16 +107,21 @@ def invoke_bastion_mode(self, bastion_settings, invocation):
logger.info('OK, remote path exists')
else:
cmd = 'mkdir -p %s' % remote_dir
mkdir = remote_sub_process.call('/', cmd)
if mkdir:
mkdir_result = remote_sub_process.call('/', cmd)
if mkdir_result:
logger.info("Performing initial sync to %s ..." % remote_dir)
sftp_sync.to_remote(local_dir, remote_dir)
rem_exists = True
rem_exists = True
else:
logger.error('Unable to create remote path!')
sys.exit(1)
logger.info('Checking for locally changed files ...')
if loc_is_git:
cmd = 'git diff-index --name-only HEAD -- && git ls-files --others --exclude-standard'
local_changed = os.popen(cmd).readlines()
else:
# If local path is not a git repo then
# we'll only sync files in the current working directory
local_changed = [f for f in os.listdir('.') if os.path.isfile(f)]
logger.info('Checking for remotely changed files ...')
no_clobber = settings.get('at_no_clobber')
Expand All @@ -130,9 +135,10 @@ def invoke_bastion_mode(self, bastion_settings, invocation):
else:
logger.error('There was a problem checking for remotely changed files')
sys.exit(1)
elif rem_exists:
else:
to_sync = list(set(local_changed))
logger.info("Performing sync to %s ..." % remote_dir)
if len(to_sync) > 0:
logger.info("Performing sync to %s ..." % remote_dir)
for path in to_sync:
dirname = os.path.dirname(path)
filename = os.path.basename(path).strip()
Expand Down

0 comments on commit 0084ce5

Please sign in to comment.