Created
May 2, 2018 18:34
-
-
Save s-hertel/6589babfed10be5f733963c326c057d0 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
--- | |
- hosts: amazon_host | |
gather_facts: yes | |
tasks: | |
- name: create target files | |
file: | |
state: touch | |
path: "{{ item }}" | |
loop: ['/tmp/onlyonremote.txt', '/tmp/existseverywhere.txt'] | |
- name: create controller files | |
file: | |
state: touch | |
path: "{{ item }}" | |
loop: ['/tmp/onlyoncontroller.txt', '/tmp/existseverywhere.txt'] | |
delegate_to: localhost | |
- name: create a bucket for the following tasks | |
aws_s3: | |
region: us-east-1 | |
mode: create | |
bucket: shertel-test-put.temp | |
################################# | |
- name: test putting an object that does not exist on controller or node in a bucket | |
aws_s3: | |
region: us-east-1 | |
bucket: shertel-test-put.temp | |
mode: put | |
src: /tmp/doesnotexistanywhere.txt | |
object: does_not_exist | |
ignore_errors: yes | |
register: failed_put | |
- assert: | |
that: | |
- failed_put is failed | |
################################# | |
# This would be a new feature rather than a bug fix | |
#- name: test putting an object that exists on the controller in a bucket | |
# aws_s3: | |
# region: us-east-1 | |
# bucket: shertel-test-put.temp | |
# mode: put | |
# src: /tmp/onlyoncontroller.txt | |
# object: exists_on_controller | |
# register: controller_put | |
#- assert: | |
# that: | |
# - controller_put is success | |
################################# | |
# This is what my patch fixes | |
- name: test putting an object that exists only on the remote node in a bucket | |
aws_s3: | |
#profile: shertel | |
region: us-east-1 | |
bucket: shertel-test-put.temp | |
mode: put | |
src: /tmp/onlyonremote.txt | |
object: exists_on_remote | |
register: target_put | |
- assert: | |
that: | |
- target_put is success | |
################################# | |
# This obviously does the same as above since the controller file is ignored | |
- name: test putting an object that exists on the controller and target in a bucket | |
aws_s3: | |
#profile: shertel | |
region: us-east-1 | |
bucket: shertel-test-put.temp | |
mode: put | |
src: /tmp/existseverywhere.txt | |
object: exists_everywhere | |
register: precedence_put | |
- assert: | |
that: | |
- precedence_put is success | |
- name: verify that the remote file was used | |
aws_s3: | |
region: us-east-1 | |
bucket: shertel-test-put.temp | |
mode: getstr | |
object: exists_everywhere | |
register: from_remote | |
# TODO add text to files to make sure correct one is uploaded if implementing copy file feature | |
#- assert: | |
# that: | |
# - "from_remote.contents.startswith('on target')" | |
################################# | |
- name: remove bucket | |
aws_s3: | |
region: us-east-1 | |
bucket: shertel-test-put.temp | |
mode: delete | |
################################# | |
- name: remove target files | |
file: | |
state: absent | |
path: "{{ item }}" | |
loop: ['/tmp/onlyonremote.txt', '/tmp/existseverywhere.txt'] | |
################################# | |
- hosts: localhost | |
connection: local | |
gather_facts: no | |
tasks: | |
- name: create a bucket for the following tasks | |
aws_s3: | |
profile: shertel | |
region: us-east-1 | |
mode: create | |
bucket: shertel-test-put.temp | |
################################# | |
- name: test putting an object that exists on the controller in a bucket | |
aws_s3: | |
profile: shertel | |
region: us-east-1 | |
bucket: shertel-test-put.temp | |
mode: put | |
src: /tmp/onlyoncontroller.txt | |
object: exists_on_controller | |
register: controller_put | |
- assert: | |
that: | |
- controller_put is success | |
################################# | |
- name: remove bucket | |
aws_s3: | |
profile: shertel | |
region: us-east-1 | |
bucket: shertel-test-put.temp | |
mode: delete | |
################################# | |
- name: remove controller files | |
file: | |
state: absent | |
path: "{{ item }}" | |
loop: ['/tmp/onlyoncontroller.txt', '/tmp/existseverywhere.txt'] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment