-
Notifications
You must be signed in to change notification settings - Fork 342
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
``aws_s3`` copy to object SUMMARY add option to aws_s3 module to copy object existing on Amazon S3 Closes: #42 ISSUE TYPE Feature Pull Request COMPONENT NAME aws_s3 ADDITIONAL INFORMATION - name: copy from source to destination aws_s3: bucket: "{{ dest }}" mode: copy object: destination.txt copy_src: bucket: "{{ src }}" object: source.txt Reviewed-by: Alina Buzachis <None> Reviewed-by: Jill R <None> Reviewed-by: Gonéri Le Bouder <[email protected]>
- Loading branch information
Showing
6 changed files
with
260 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
minor_changes: | ||
- aws_s3 - new mode to copy existing on another bucket (https://github.com/ansible-collections/amazon.aws/pull/359). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
- block: | ||
- name: define bucket name used for tests | ||
set_fact: | ||
copy_bucket: | ||
src: "{{ bucket_name }}-copysrc" | ||
dst: "{{ bucket_name }}-copydst" | ||
|
||
- name: create bucket source | ||
aws_s3: | ||
bucket: "{{ copy_bucket.src }}" | ||
mode: create | ||
|
||
- name: Create content | ||
set_fact: | ||
content: "{{ lookup('password', '/dev/null chars=ascii_letters,digits,hexdigits,punctuation') }}" | ||
|
||
- name: Put a content in the source bucket | ||
aws_s3: | ||
bucket: "{{ copy_bucket.src }}" | ||
mode: put | ||
content: "{{ content }}" | ||
object: source.txt | ||
tags: | ||
ansible_release: '2.0.0' | ||
ansible_team: cloud | ||
retries: 3 | ||
delay: 3 | ||
register: put_result | ||
until: "put_result.msg == 'PUT operation complete'" | ||
|
||
- name: Copy the content of the source bucket into dest bucket | ||
aws_s3: | ||
bucket: "{{ copy_bucket.dst }}" | ||
mode: copy | ||
object: destination.txt | ||
copy_src: | ||
bucket: "{{ copy_bucket.src }}" | ||
object: source.txt | ||
|
||
- name: Get the content copied into {{ copy_bucket.dst }} | ||
aws_s3: | ||
bucket: "{{ copy_bucket.dst }}" | ||
mode: getstr | ||
object: destination.txt | ||
register: copy_content | ||
|
||
- name: assert that the content is matching with the source | ||
assert: | ||
that: | ||
- content == copy_content.contents | ||
|
||
- name: Get the download url for object copied into {{ copy_bucket.dst }} | ||
aws_s3: | ||
bucket: "{{ copy_bucket.dst }}" | ||
mode: geturl | ||
object: destination.txt | ||
register: copy_url | ||
|
||
- name: assert that tags are the same in the destination bucket | ||
assert: | ||
that: | ||
- put_result.tags == copy_url.tags | ||
|
||
- name: Copy the same content from the source bucket into dest bucket (idempotency) | ||
aws_s3: | ||
bucket: "{{ copy_bucket.dst }}" | ||
mode: copy | ||
object: destination.txt | ||
copy_src: | ||
bucket: "{{ copy_bucket.src }}" | ||
object: source.txt | ||
register: copy_idempotency | ||
|
||
- name: assert that no change was made | ||
assert: | ||
that: | ||
- copy_idempotency is not changed | ||
- "copy_idempotency.msg == 'ETag from source and destination are the same'" | ||
|
||
- name: Copy object with tags | ||
aws_s3: | ||
bucket: "{{ copy_bucket.dst }}" | ||
mode: copy | ||
object: destination.txt | ||
tags: | ||
ansible_release: "2.0.1" | ||
copy_src: | ||
bucket: "{{ copy_bucket.src }}" | ||
object: source.txt | ||
register: copy_result | ||
|
||
- name: assert that tags were updated | ||
assert: | ||
that: | ||
- copy_result is changed | ||
- copy_result.tags['ansible_release'] == '2.0.1' | ||
|
||
- name: Copy object with tags (idempotency) | ||
aws_s3: | ||
bucket: "{{ copy_bucket.dst }}" | ||
mode: copy | ||
object: destination.txt | ||
tags: | ||
ansible_release: "2.0.1" | ||
copy_src: | ||
bucket: "{{ copy_bucket.src }}" | ||
object: source.txt | ||
register: copy_result | ||
|
||
- name: assert that no change was made | ||
assert: | ||
that: | ||
- copy_result is not changed | ||
|
||
always: | ||
- include_tasks: delete_bucket.yml | ||
with_items: | ||
- "{{ copy_bucket.dst }}" | ||
- "{{ copy_bucket.src }}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.