From cf40025b24d4a77548fb849b07c843b8417e2962 Mon Sep 17 00:00:00 2001 From: abikouo Date: Thu, 6 May 2021 18:33:32 +0200 Subject: [PATCH] s3 copy_object Update and rename 357-aws_s3-add-copy-mode.yml to 359-aws_s3-add-copy-mode.yml --- ...-mode.yml => 359-aws_s3-add-copy-mode.yml} | 2 +- plugins/modules/aws_s3.py | 13 +--------- .../targets/aws_s3/tasks/copy_object.yml | 8 ++----- .../targets/aws_s3/tasks/delete_bucket.yml | 24 +++++++++++++++++++ 4 files changed, 28 insertions(+), 19 deletions(-) rename changelogs/fragments/{357-aws_s3-add-copy-mode.yml => 359-aws_s3-add-copy-mode.yml} (59%) create mode 100644 tests/integration/targets/aws_s3/tasks/delete_bucket.yml diff --git a/changelogs/fragments/357-aws_s3-add-copy-mode.yml b/changelogs/fragments/359-aws_s3-add-copy-mode.yml similarity index 59% rename from changelogs/fragments/357-aws_s3-add-copy-mode.yml rename to changelogs/fragments/359-aws_s3-add-copy-mode.yml index 56b7b80da4c..1c9c4145ddd 100644 --- a/changelogs/fragments/357-aws_s3-add-copy-mode.yml +++ b/changelogs/fragments/359-aws_s3-add-copy-mode.yml @@ -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). diff --git a/plugins/modules/aws_s3.py b/plugins/modules/aws_s3.py index cdb377046db..20c9d4512b0 100644 --- a/plugins/modules/aws_s3.py +++ b/plugins/modules/aws_s3.py @@ -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. @@ -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)" @@ -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 @@ -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 @@ -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): diff --git a/tests/integration/targets/aws_s3/tasks/copy_object.yml b/tests/integration/targets/aws_s3/tasks/copy_object.yml index b8fef173c55..b60572ff03d 100644 --- a/tests/integration/targets/aws_s3/tasks/copy_object.yml +++ b/tests/integration/targets/aws_s3/tasks/copy_object.yml @@ -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 \ No newline at end of file + - "{{ copy_bucket.src }}" diff --git a/tests/integration/targets/aws_s3/tasks/delete_bucket.yml b/tests/integration/targets/aws_s3/tasks/delete_bucket.yml new file mode 100644 index 00000000000..bb6bca52ff8 --- /dev/null +++ b/tests/integration/targets/aws_s3/tasks/delete_bucket.yml @@ -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