2017-05-31 15:48:35 +00:00
|
|
|
---
|
|
|
|
# tasks file for test_s3
|
|
|
|
# ============================================================
|
2018-01-09 23:05:22 +00:00
|
|
|
- name: set up aws connection info
|
|
|
|
set_fact:
|
|
|
|
aws_connection_info: &aws_connection_info
|
|
|
|
aws_access_key: "{{ aws_access_key }}"
|
|
|
|
aws_secret_key: "{{ aws_secret_key }}"
|
|
|
|
security_token: "{{ security_token }}"
|
|
|
|
region: "{{ aws_region }}"
|
|
|
|
no_log: yes
|
|
|
|
# ============================================================
|
2017-05-31 15:48:35 +00:00
|
|
|
- name: test create bucket
|
2017-10-26 12:17:13 +00:00
|
|
|
aws_s3:
|
2017-09-15 09:08:09 +00:00
|
|
|
bucket: "{{ bucket_name }}"
|
2017-05-31 15:48:35 +00:00
|
|
|
mode: create
|
2018-01-09 23:05:22 +00:00
|
|
|
<<: *aws_connection_info
|
2017-05-31 15:48:35 +00:00
|
|
|
register: result
|
|
|
|
- name: assert changed is True
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- result.changed == True
|
|
|
|
# ============================================================
|
|
|
|
- name: trying to create a bucket name that already exists
|
2017-10-26 12:17:13 +00:00
|
|
|
aws_s3:
|
2017-09-15 09:08:09 +00:00
|
|
|
bucket: "{{ bucket_name }}"
|
2017-05-31 15:48:35 +00:00
|
|
|
mode: create
|
2018-01-09 23:05:22 +00:00
|
|
|
<<: *aws_connection_info
|
2017-05-31 15:48:35 +00:00
|
|
|
register: result
|
|
|
|
- name: assert changed is False since the bucket already exists
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- result.changed == False
|
|
|
|
# ============================================================
|
|
|
|
- name: create temporary file object to put in a bucket
|
|
|
|
tempfile:
|
|
|
|
register: tmp1
|
|
|
|
- name: make random contents
|
|
|
|
set_fact:
|
|
|
|
content: "{{ lookup('password', '/dev/null chars=ascii_letters,digits,hexdigits,punctuation') }}"
|
|
|
|
|
|
|
|
- name: give temporary file data
|
|
|
|
copy:
|
|
|
|
content: "{{ content }}"
|
|
|
|
dest: "{{ tmp1.path }}"
|
|
|
|
- name: get the stat of the file
|
|
|
|
stat:
|
|
|
|
path: "{{ tmp1.path }}"
|
|
|
|
get_checksum: yes
|
|
|
|
register: file1stat
|
|
|
|
# ============================================================
|
|
|
|
- name: test putting an object in the bucket
|
2017-10-26 12:17:13 +00:00
|
|
|
aws_s3:
|
2017-09-15 09:08:09 +00:00
|
|
|
bucket: "{{ bucket_name }}"
|
2017-05-31 15:48:35 +00:00
|
|
|
mode: put
|
|
|
|
src: "{{ tmp1.path }}"
|
|
|
|
object: delete.txt
|
2018-01-09 23:05:22 +00:00
|
|
|
<<: *aws_connection_info
|
2017-05-31 15:48:35 +00:00
|
|
|
retries: 3
|
|
|
|
delay: 3
|
|
|
|
register: result
|
|
|
|
- name: assert object exists
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- result.changed == True
|
|
|
|
- result.msg == "PUT operation complete"
|
|
|
|
# ============================================================
|
2018-06-08 00:12:13 +00:00
|
|
|
- name: test using aws_s3 with async
|
|
|
|
aws_s3:
|
|
|
|
bucket: "{{ bucket_name }}"
|
|
|
|
mode: put
|
|
|
|
src: "{{ tmp1.path }}"
|
|
|
|
object: delete.txt
|
|
|
|
<<: *aws_connection_info
|
|
|
|
register: test_async
|
|
|
|
async: 30
|
|
|
|
poll: 0
|
|
|
|
- name: ensure it completed
|
|
|
|
async_status:
|
|
|
|
jid: "{{ test_async.ansible_job_id }}"
|
|
|
|
register: status
|
|
|
|
until: status.finished
|
|
|
|
retries: 10
|
|
|
|
# ============================================================
|
2018-01-19 22:11:42 +00:00
|
|
|
- name: check that roles file lookups work as expected
|
|
|
|
aws_s3:
|
|
|
|
bucket: "{{ bucket_name }}"
|
|
|
|
mode: put
|
|
|
|
src: hello.txt
|
|
|
|
object: hello.txt
|
|
|
|
<<: *aws_connection_info
|
|
|
|
retries: 3
|
|
|
|
delay: 3
|
|
|
|
register: result
|
|
|
|
- name: assert object exists
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- result.changed == True
|
|
|
|
- result.msg == "PUT operation complete"
|
|
|
|
- name: remove hello.txt (deletion tests are later)
|
|
|
|
aws_s3:
|
|
|
|
bucket: "{{ bucket_name }}"
|
|
|
|
mode: delobj
|
|
|
|
object: hello.txt
|
|
|
|
<<: *aws_connection_info
|
|
|
|
retries: 3
|
|
|
|
delay: 3
|
|
|
|
register: result
|
|
|
|
# ============================================================
|
2017-05-31 15:48:35 +00:00
|
|
|
- name: create a second temp file to download the object from the bucket
|
|
|
|
tempfile:
|
|
|
|
register: tmp2
|
|
|
|
- name: test get object
|
2017-10-26 12:17:13 +00:00
|
|
|
aws_s3:
|
2017-09-15 09:08:09 +00:00
|
|
|
bucket: "{{ bucket_name }}"
|
2017-05-31 15:48:35 +00:00
|
|
|
mode: get
|
|
|
|
dest: "{{ tmp2.path }}"
|
|
|
|
object: delete.txt
|
2018-01-09 23:05:22 +00:00
|
|
|
<<: *aws_connection_info
|
2017-05-31 15:48:35 +00:00
|
|
|
retries: 3
|
|
|
|
delay: 3
|
|
|
|
register: result
|
2017-09-15 09:08:09 +00:00
|
|
|
until: "result.msg == 'GET operation complete'"
|
2017-05-31 15:48:35 +00:00
|
|
|
- name: get the stat of the file so we can compare the checksums
|
|
|
|
stat:
|
|
|
|
path: "{{ tmp2.path }}"
|
|
|
|
get_checksum: yes
|
|
|
|
register: file2stat
|
|
|
|
- name: assert checksums are the same
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- file1stat.stat.checksum == file2stat.stat.checksum
|
|
|
|
# ============================================================
|
|
|
|
- name: test geturl of the object
|
2017-10-26 12:17:13 +00:00
|
|
|
aws_s3:
|
2017-09-15 09:08:09 +00:00
|
|
|
bucket: "{{ bucket_name }}"
|
2017-05-31 15:48:35 +00:00
|
|
|
mode: geturl
|
|
|
|
object: delete.txt
|
2018-01-09 23:05:22 +00:00
|
|
|
<<: *aws_connection_info
|
2017-05-31 15:48:35 +00:00
|
|
|
retries: 3
|
|
|
|
delay: 3
|
|
|
|
register: result
|
2017-09-15 09:08:09 +00:00
|
|
|
until: result.changed
|
2017-05-31 15:48:35 +00:00
|
|
|
- name: assert we have the object's url
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- "'Download url:' in result.msg"
|
|
|
|
- result.changed == True
|
|
|
|
# ============================================================
|
|
|
|
- name: test getstr of the object
|
2017-10-26 12:17:13 +00:00
|
|
|
aws_s3:
|
2017-09-15 09:08:09 +00:00
|
|
|
bucket: "{{ bucket_name }}"
|
2017-05-31 15:48:35 +00:00
|
|
|
mode: getstr
|
|
|
|
object: delete.txt
|
2018-01-09 23:05:22 +00:00
|
|
|
<<: *aws_connection_info
|
2017-05-31 15:48:35 +00:00
|
|
|
retries: 3
|
|
|
|
delay: 3
|
|
|
|
register: result
|
|
|
|
- name: assert that we have the object's contents
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- result.msg == "GET operation complete"
|
|
|
|
- result.contents == content
|
|
|
|
# ============================================================
|
|
|
|
- name: test list to get all objects in the bucket
|
2017-10-26 12:17:13 +00:00
|
|
|
aws_s3:
|
2017-09-15 09:08:09 +00:00
|
|
|
bucket: "{{ bucket_name }}"
|
2017-05-31 15:48:35 +00:00
|
|
|
mode: list
|
2018-01-09 23:05:22 +00:00
|
|
|
<<: *aws_connection_info
|
2017-05-31 15:48:35 +00:00
|
|
|
retries: 3
|
|
|
|
delay: 3
|
|
|
|
register: result
|
|
|
|
- name: assert that the keys are correct
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- "'delete.txt' in result.s3_keys"
|
|
|
|
- result.msg == "LIST operation complete"
|
|
|
|
# ============================================================
|
|
|
|
- name: test delobj to just delete an object in the bucket
|
2017-10-26 12:17:13 +00:00
|
|
|
aws_s3:
|
2017-09-15 09:08:09 +00:00
|
|
|
bucket: "{{ bucket_name }}"
|
2017-05-31 15:48:35 +00:00
|
|
|
mode: delobj
|
|
|
|
object: delete.txt
|
2018-01-09 23:05:22 +00:00
|
|
|
<<: *aws_connection_info
|
2017-05-31 15:48:35 +00:00
|
|
|
retries: 3
|
|
|
|
delay: 3
|
|
|
|
register: result
|
|
|
|
- name: assert that delete.txt is no longer an object in the bucket deleteme
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- "'Object deleted from bucket' in result.msg"
|
|
|
|
- result.changed == True
|
2017-10-26 12:17:13 +00:00
|
|
|
- name: assert that delete.txt is no longer an object in the bucket deleteme
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- "'Object deleted from bucket' in result.msg"
|
|
|
|
- result.changed == True
|
|
|
|
# ============================================================
|
|
|
|
- name: test creation of empty path
|
|
|
|
aws_s3:
|
|
|
|
bucket: "{{ bucket_name }}"
|
|
|
|
mode: create
|
|
|
|
object: foo/bar/baz/
|
2018-01-09 23:05:22 +00:00
|
|
|
<<: *aws_connection_info
|
2017-10-26 12:17:13 +00:00
|
|
|
retries: 3
|
|
|
|
delay: 3
|
|
|
|
register: result
|
|
|
|
- name: assert that empty path is created
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- "'Virtual directory foo/bar/baz/ created' in result.msg"
|
|
|
|
- result.changed == True
|
|
|
|
- name: test deletion of empty path
|
|
|
|
aws_s3:
|
|
|
|
bucket: "{{ bucket_name }}"
|
|
|
|
mode: delobj
|
|
|
|
object: foo/bar/baz/
|
2018-01-09 23:05:22 +00:00
|
|
|
<<: *aws_connection_info
|
2017-10-26 12:17:13 +00:00
|
|
|
retries: 3
|
|
|
|
delay: 3
|
2017-05-31 15:48:35 +00:00
|
|
|
# ============================================================
|
|
|
|
- name: test delete bucket
|
2017-10-26 12:17:13 +00:00
|
|
|
aws_s3:
|
2017-09-15 09:08:09 +00:00
|
|
|
bucket: "{{ bucket_name }}"
|
2017-05-31 15:48:35 +00:00
|
|
|
mode: delete
|
2018-01-09 23:05:22 +00:00
|
|
|
<<: *aws_connection_info
|
2017-05-31 15:48:35 +00:00
|
|
|
register: result
|
2017-09-15 09:08:09 +00:00
|
|
|
retries: 3
|
|
|
|
delay: 3
|
|
|
|
until: result.changed
|
2017-05-31 15:48:35 +00:00
|
|
|
- name: assert that changed is True
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- result.changed == True
|
|
|
|
# ============================================================
|
|
|
|
- name: delete temporary file 1
|
|
|
|
file:
|
|
|
|
state: absent
|
|
|
|
path: "{{ tmp1.path }}"
|
|
|
|
- name: delete temporary file 2
|
|
|
|
file:
|
|
|
|
state: absent
|
|
|
|
path: "{{ tmp2.path }}"
|
|
|
|
# ============================================================
|
|
|
|
- name: test create a bucket with a dot in the name
|
2017-10-26 12:17:13 +00:00
|
|
|
aws_s3:
|
2017-09-15 09:08:09 +00:00
|
|
|
bucket: "{{ bucket_name + '.bucket' }}"
|
2017-05-31 15:48:35 +00:00
|
|
|
mode: create
|
2018-01-09 23:05:22 +00:00
|
|
|
<<: *aws_connection_info
|
2017-05-31 15:48:35 +00:00
|
|
|
register: result
|
|
|
|
- name: assert that changed is True
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- result.changed == True
|
|
|
|
# ============================================================
|
|
|
|
- name: test delete a bucket with a dot in the name
|
2017-10-26 12:17:13 +00:00
|
|
|
aws_s3:
|
2017-09-15 09:08:09 +00:00
|
|
|
bucket: "{{ bucket_name + '.bucket' }}"
|
2017-05-31 15:48:35 +00:00
|
|
|
mode: delete
|
2018-01-09 23:05:22 +00:00
|
|
|
<<: *aws_connection_info
|
2017-05-31 15:48:35 +00:00
|
|
|
register: result
|
|
|
|
- name: assert that changed is True
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- result.changed == True
|
|
|
|
# ============================================================
|
2017-06-12 17:52:25 +00:00
|
|
|
- name: test delete a nonexistent bucket
|
2017-10-26 12:17:13 +00:00
|
|
|
aws_s3:
|
2017-09-15 09:08:09 +00:00
|
|
|
bucket: "{{ bucket_name + '.bucket' }}"
|
2017-06-12 17:52:25 +00:00
|
|
|
mode: delete
|
2018-01-09 23:05:22 +00:00
|
|
|
<<: *aws_connection_info
|
2017-06-12 17:52:25 +00:00
|
|
|
register: result
|
|
|
|
- name: assert that changed is False
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- result.changed == False
|
|
|
|
# ============================================================
|
2018-01-09 23:05:22 +00:00
|
|
|
- name: create a tempfile for the path
|
|
|
|
tempfile:
|
|
|
|
register: tmp1
|
|
|
|
|
|
|
|
- name: make tempfile 4 GB for OSX
|
|
|
|
command:
|
|
|
|
_raw_params: "dd if=/dev/zero of={{ tmp1.path }} bs=1m count=4096"
|
|
|
|
when: ansible_distribution == 'MacOSX'
|
|
|
|
|
|
|
|
- name: make tempfile 4 GB for linux
|
|
|
|
command:
|
|
|
|
_raw_params: "dd if=/dev/zero of={{ tmp1.path }} bs=1M count=4096"
|
|
|
|
when: ansible_distribution == 'Linux'
|
|
|
|
|
|
|
|
- name: test multipart download - platform specific
|
|
|
|
block:
|
|
|
|
- name: make a bucket to upload the file
|
|
|
|
aws_s3:
|
|
|
|
bucket: "{{ bucket_name }}"
|
|
|
|
mode: create
|
|
|
|
<<: *aws_connection_info
|
|
|
|
|
|
|
|
- name: upload the file to the bucket
|
|
|
|
aws_s3:
|
|
|
|
bucket: "{{ bucket_name }}"
|
|
|
|
mode: put
|
|
|
|
src: "{{ tmp1.path }}"
|
|
|
|
object: multipart.txt
|
|
|
|
<<: *aws_connection_info
|
|
|
|
|
|
|
|
- name: download file once
|
|
|
|
aws_s3:
|
|
|
|
bucket: "{{ bucket_name }}"
|
|
|
|
mode: get
|
|
|
|
dest: /tmp/multipart_download.txt
|
|
|
|
object: multipart.txt
|
|
|
|
overwrite: different
|
|
|
|
<<: *aws_connection_info
|
|
|
|
retries: 3
|
|
|
|
delay: 3
|
|
|
|
until: "result.msg == 'GET operation complete'"
|
|
|
|
register: result
|
|
|
|
|
|
|
|
- name: assert the file was downloaded once
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- result.changed
|
|
|
|
|
|
|
|
- name: download file again
|
|
|
|
aws_s3:
|
|
|
|
bucket: "{{ bucket_name }}"
|
|
|
|
mode: get
|
|
|
|
dest: /tmp/multipart_download.txt
|
|
|
|
object: multipart.txt
|
|
|
|
overwrite: different
|
|
|
|
<<: *aws_connection_info
|
|
|
|
register: result
|
|
|
|
|
|
|
|
- name: assert the file was not redownloaded
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- not result.changed
|
|
|
|
|
|
|
|
- name: delete file used for upload
|
|
|
|
file:
|
|
|
|
state: absent
|
|
|
|
path: "{{ tmp1.path }}"
|
|
|
|
|
|
|
|
- name: delete downloaded file
|
|
|
|
file:
|
|
|
|
state: absent
|
|
|
|
path: /tmp/multipart_download.txt
|
|
|
|
|
|
|
|
- name: delete the bucket
|
|
|
|
aws_s3:
|
|
|
|
bucket: "{{ bucket_name }}"
|
|
|
|
mode: delete
|
|
|
|
<<: *aws_connection_info
|
|
|
|
|
|
|
|
when: ansible_distribution in ['MacOSX', 'Linux']
|
|
|
|
# ============================================================
|