diff --git a/ansible_taskrunner/libs/providers/ansible.py b/ansible_taskrunner/libs/providers/ansible.py index 7c6cada..9e94d79 100644 --- a/ansible_taskrunner/libs/providers/ansible.py +++ b/ansible_taskrunner/libs/providers/ansible.py @@ -148,7 +148,7 @@ def invoke_bastion_mode(self, bastion_settings, invocation, remote_command, kwar 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' + cmd = '''(git diff-index HEAD --name-status | awk '$1 != "D" {print $2}') && git ls-files --others --exclude-standard''' local_changed = os.popen(cmd).readlines() else: # If local path is not a git repo then @@ -171,6 +171,7 @@ def invoke_bastion_mode(self, bastion_settings, invocation, remote_command, kwar sys.exit(1) else: to_sync = list(set(local_changed)) + logger.debug('Files to sync: %s' % ' '.join(to_sync)) if len(to_sync) > 0: logger.info("Performing sync to %s ..." % remote_dir) for path in to_sync: diff --git a/ansible_taskrunner/libs/sshutil/sync.py b/ansible_taskrunner/libs/sshutil/sync.py index 73b6fcc..dce665f 100644 --- a/ansible_taskrunner/libs/sshutil/sync.py +++ b/ansible_taskrunner/libs/sshutil/sync.py @@ -20,6 +20,7 @@ try: import paramiko from paramiko import SSHClient, ssh_exception + from libs.sshutil.scp import SCPException except ImportError as e: print('Error in %s ' % os.path.basename(self_file_name)) print('Failed to import at least one required module') @@ -49,12 +50,15 @@ def create_parent_dirs(self, remote_path): self.sftp_obj.stat(directory) def to_remote(self, local_path, remote_path): - logger.debug("Lcl Sync Target {}".format(local_path)) - logger.debug("Rmt Sync Target {}".format(remote_path)) + logger.debug("Loc Sync Target {}".format(local_path)) + logger.debug("Rem Sync Target {}".format(remote_path)) if os.path.exists(local_path): - self.create_parent_dirs(remote_path) - self.scp.put(local_path, remote_path=remote_path, preserve_times=True, recursive=True) - logger.debug("Successfully copied to remote.") + try: + self.create_parent_dirs(remote_path) + self.scp.put(local_path, remote_path=remote_path, preserve_times=True, recursive=True) + logger.debug('Sync ok for %s' % local_path) + except SCPException as e: + logger.error('Failed to sync {} to remote {} - error was {}'.format(local_path, remote_path, e)) else: logger.warning("Skipping %s as it does not exist" % local_path.strip()) return