Skip to content

Commit

Permalink
workaround until ansible-collections#113 is fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
anthonybgale authored and anthonybgale committed Jul 14, 2022
1 parent 1f61cfb commit b73d612
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions plugins/connection/aws_ssm.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,10 @@ def start_session(self):
def exec_command(self, cmd, in_data=None, sudoable=True):
''' run a command on the ssm host '''

# demangle
cmd = ''.join(cmd.split('"` echo '))
cmd = ''.join(cmd.split(' `" )'))

super(Connection, self).exec_command(cmd, in_data=in_data, sudoable=sudoable)

display.vvv(u"EXEC {0}".format(to_text(cmd)), host=self.host)
Expand Down Expand Up @@ -490,7 +494,13 @@ def _post_process(self, stdout, mark_begin):
return (returncode, stdout)
else:
# Get command return code
returncode = int(stdout.splitlines()[-2])
# returncode = int(stdout.splitlines()[-2])

# workaround until https://github.com/ansible-collections/community.aws/issues/113 is fixed
try:
returncode = int(stdout.splitlines()[-2])
except:
returncode = 0

# Throw away ending lines
for x in range(0, 3):
Expand Down Expand Up @@ -582,6 +592,7 @@ def _get_boto_client(self, service, region_name=None, profile_name=None):
def _file_transport_command(self, in_path, out_path, ssm_action):
''' transfer a file from using an intermediate S3 bucket '''


path_unescaped = u"{0}/{1}".format(self.instance_id, out_path)
s3_path = path_unescaped.replace('\\', '/')
bucket_url = 's3://%s/%s' % (self.get_option('bucket_name'), s3_path)
Expand Down Expand Up @@ -611,7 +622,7 @@ def _file_transport_command(self, in_path, out_path, ssm_action):
put_command_headers, in_path,
self._get_url('put_object', self.get_option('bucket_name'), s3_path, 'PUT', profile_name,
extra_args=put_args))
get_command = "curl '%s' -o '%s'" % (
get_command = "curl '%s' --create-dirs -o '%s'" % (
self._get_url('get_object', self.get_option('bucket_name'), s3_path, 'GET', profile_name), out_path)

client = self._get_boto_client('s3', profile_name=profile_name)
Expand All @@ -637,6 +648,11 @@ def _file_transport_command(self, in_path, out_path, ssm_action):
def put_file(self, in_path, out_path):
''' transfer a file from local to remote '''

# demangle
out_path = out_path.lstrip('"` echo ')
out_path = ''.join(out_path.split(' `" )'))


super(Connection, self).put_file(in_path, out_path)

display.vvv(u"PUT {0} TO {1}".format(in_path, out_path), host=self.host)
Expand Down

0 comments on commit b73d612

Please sign in to comment.