Debian Codegraph @

ansible_collections/amazon/aws/tests/integration/targets/s3_object/tasks/copy_recursively.yml

raw
1 ---
2 - name: Test copy recursively object from one bucket to another one.
3 vars:
4 bucket_src: "{{ bucket_name }}-recursive-src"
5 bucket_dst: "{{ bucket_name }}-recursive-dst"
6 s3_objects:
7 - object: file1.txt
8 content: |
9 some content for file1.txt
10 - object: file2.txt
11 content: |
12 some content for file2.txt
13 - object: file3.txt
14 content: |
15 some content for file3.txt
16 - object: testfile.py
17 content: This is a sample text file
18 - object: another.txt
19 content: another file to create into bucket
20
21 block:
22 - name: Create S3 bucket
23 amazon.aws.s3_bucket:
24 name: "{{ item }}"
25 state: present
26 with_items:
27 - "{{ bucket_src }}"
28 - "{{ bucket_dst }}"
29
30 - name: Create object into bucket
31 amazon.aws.s3_object:
32 bucket: "{{ bucket_src }}"
33 mode: put
34 content: "{{ item.content }}"
35 object: "{{ item.object }}"
36 with_items: "{{ s3_objects }}"
37
38 - name: Copy all objects from source bucket into destination bucket
39 amazon.aws.s3_object:
40 bucket: "{{ bucket_dst }}"
41 mode: copy
42 copy_src:
43 bucket: "{{ bucket_src }}"
44 check_mode: true
45
46 - name: List objects from bucket
47 amazon.aws.s3_object_info:
48 bucket_name: "{{ bucket_dst }}"
49 register: _objects
50
51 - name: Ensure no object were found into bucket
52 ansible.builtin.assert:
53 that:
54 - _objects.s3_keys | length == 0
55
56 # Test: Copy all objects using prefix
57 - name: Copy object using prefix
58 amazon.aws.s3_object:
59 bucket: "{{ bucket_dst }}"
60 mode: copy
61 copy_src:
62 bucket: "{{ bucket_src }}"
63 prefix: file
64 register: _copy_with_prefix
65
66 - name: List objects from bucket
67 amazon.aws.s3_object_info:
68 bucket_name: "{{ bucket_dst }}"
69 register: _objects
70
71 - name: Ensure objects with prefix 'file' were copied into bucket
72 ansible.builtin.assert:
73 that:
74 - _copy_with_prefix is changed
75 - _objects.s3_keys | length == 3
76 - '"file1.txt" in _objects.s3_keys'
77 - '"file2.txt" in _objects.s3_keys'
78 - '"file3.txt" in _objects.s3_keys'
79
80 # Test: Copy all objects using prefix (idempotency)
81 - name: Copy object using prefix (idempotency)
82 amazon.aws.s3_object:
83 bucket: "{{ bucket_dst }}"
84 mode: copy
85 copy_src:
86 bucket: "{{ bucket_src }}"
87 prefix: file
88 register: _copy_with_prefix_idempotency
89
90 - name: List objects from bucket
91 amazon.aws.s3_object_info:
92 bucket_name: "{{ bucket_dst }}"
93 register: _objects
94
95 - name: Ensure objects with prefix 'file' were copied into bucket
96 ansible.builtin.assert:
97 that:
98 - _copy_with_prefix_idempotency is not changed
99 - _objects.s3_keys | length == 3
100 - '"file1.txt" in _objects.s3_keys'
101 - '"file2.txt" in _objects.s3_keys'
102 - '"file3.txt" in _objects.s3_keys'
103
104 - name: Test list to get just 1 object from the bucket
105 amazon.aws.s3_object_info:
106 bucket_name: "{{ bucket_dst }}"
107 max_keys: 1
108 retries: 3
109 delay: 3
110 register: result
111
112 - ansible.builtin.assert:
113 that:
114 - "(result.s3_keys | length) == 1"
115
116 # Test: Copy all objects from source bucket
117 - name: Copy all objects from source bucket
118 amazon.aws.s3_object:
119 bucket: "{{ bucket_dst }}"
120 mode: copy
121 copy_src:
122 bucket: "{{ bucket_src }}"
123 register: _copy_all
124
125 - name: List objects from bucket
126 amazon.aws.s3_object_info:
127 bucket_name: "{{ bucket_dst }}"
128 register: _objects
129
130 - name: Ensure all objects were copied into bucket
131 ansible.builtin.assert:
132 that:
133 - _copy_all is changed
134 - _objects.s3_keys | length == 5
135
136 # Test: Copy all objects from source bucket (idempotency)
137 - name: Copy all objects from source bucket (idempotency)
138 amazon.aws.s3_object:
139 bucket: "{{ bucket_dst }}"
140 mode: copy
141 copy_src:
142 bucket: "{{ bucket_src }}"
143 register: _copy_all_idempotency
144
145 - name: List objects from bucket
146 amazon.aws.s3_object_info:
147 bucket_name: "{{ bucket_dst }}"
148 register: _objects
149
150 - name: Ensure number of copied objects remains the same.
151 ansible.builtin.assert:
152 that:
153 - _copy_all_idempotency is not changed
154 - _objects.s3_keys | length == 5
155
156 always:
157 - ansible.builtin.include_tasks: delete_bucket.yml
158 with_items:
159 - "{{ bucket_src }}"
160 - "{{ bucket_dst }}"