Skip to content

Commit

Permalink
s3 copy_object
Browse files Browse the repository at this point in the history
Update and rename 357-aws_s3-add-copy-mode.yml to 359-aws_s3-add-copy-mode.yml
  • Loading branch information
abikouo committed May 25, 2021
1 parent bbce073 commit cf40025
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 19 deletions.
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
minor_changes:
- aws_s3 - new mode to copy existing on another bucket (https://github.com/ansible-collections/amazon.aws/pull/356).
- aws_s3 - new mode to copy existing on another bucket (https://github.com/ansible-collections/amazon.aws/pull/359).
13 changes: 1 addition & 12 deletions plugins/modules/aws_s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,6 @@
description:
- KMS key id to use when encrypting objects using I(encrypting=aws:kms). Ignored if I(encryption) is not C(aws:kms).
type: str
<<<<<<< HEAD
=======
copy_src:
description:
- The source details of the object to copy.
Expand All @@ -180,7 +178,6 @@
description:
- version ID of the source object.
requirements: [ "boto3", "botocore" ]
>>>>>>> 0176b7e (s3 copy_object)
author:
- "Lester Wade (@lwade)"
- "Sloane Hertel (@s-hertel)"
Expand Down Expand Up @@ -331,13 +328,6 @@
- prefix1/
- prefix1/key1
- prefix1/key2
copy_object_result:
description: result of the copy operation.
returned: (for copy operation)
type: dict
sample:
e_tag: "\"eb354219cd15668c7a70221cda545c82\""
last_modified: "2021-05-06T15:42:32+00:00"
'''

import mimetypes
Expand All @@ -354,7 +344,6 @@
from ansible.module_utils.basic import to_text
from ansible.module_utils.basic import to_native
from ansible.module_utils.six.moves.urllib.parse import urlparse
from ansible.module_utils.common.dict_transformations import camel_dict_to_snake_dict

from ..module_utils.core import AnsibleAWSModule
from ..module_utils.core import is_boto3_error_code
Expand Down Expand Up @@ -715,7 +704,7 @@ def copy_object_to_bucket(module, s3, bucket, obj, encrypt, metadata, validate,
module.warn("PutObjectAcl is not implemented by your storage provider. Set the permissions parameters to the empty list to avoid this warning")
except (botocore.exceptions.BotoCoreError, botocore.exceptions.ClientError) as e: # pylint: disable=duplicate-except
module.fail_json_aws(e, msg="Failed while copying object %s from bucket %s." % (obj, module.params['copy_src'].get('Bucket')))
module.exit_json(msg="COPY operation complete", changed=True, copy_object_result=camel_dict_to_snake_dict(copy_result['CopyObjectResult']))
module.exit_json(msg="Object copied from bucket %s to bucket %s." % (bucketsrc['Bucket'], bucket), changed=True)


def is_fakes3(s3_url):
Expand Down
8 changes: 2 additions & 6 deletions tests/integration/targets/aws_s3/tasks/copy_object.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,7 @@
- "copy_idempotency.msg == 'ETag from source and destination are the same'"

always:
- name: delete bucket created
aws_s3:
bucket: "{{ item }}"
mode: delete
- include_tasks: delete_bucket.yml
with_items:
- "{{ copy_bucket.src }}"
- "{{ copy_bucket.dst }}"
ignore_errors: yes
- "{{ copy_bucket.src }}"
24 changes: 24 additions & 0 deletions tests/integration/targets/aws_s3/tasks/delete_bucket.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
- name: delete bucket at the end of Integration tests
block:
- name: list bucket object
aws_s3:
bucket: "{{ item }}"
mode: list
register: objects
ignore_errors: true

- name: remove objects from bucket
aws_s3:
bucket: "{{ item }}"
mode: delobj
object: "{{ obj }}"
with_items: "{{ objects.s3_keys }}"
loop_control:
loop_var: obj
ignore_errors: true

- name: delete the bucket
aws_s3:
bucket: "{{ item }}"
mode: delete
ignore_errors: yes

0 comments on commit cf40025

Please sign in to comment.