Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[cloud] Bugfix for aws_s3 empty directory creation #32198

Merged
merged 3 commits into from
Oct 26, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 4 additions & 5 deletions lib/ansible/modules/cloud/amazon/aws_s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,8 @@ def delete_bucket(module, s3, bucket):
# if there are contents then we need to delete them before we can delete the bucket
for keys in paginated_list(s3, Bucket=bucket):
formatted_keys = [{'Key': key} for key in keys]
s3.delete_objects(Bucket=bucket, Delete={'Objects': formatted_keys})
if formatted_keys:
s3.delete_objects(Bucket=bucket, Delete={'Objects': formatted_keys})
s3.delete_bucket(Bucket=bucket)
return True
except botocore.exceptions.ClientError as e:
Expand All @@ -375,12 +376,10 @@ def create_dirkey(module, s3, bucket, obj):
if module.check_mode:
module.exit_json(msg="PUT operation skipped - running in check mode", changed=True)
try:
bucket = s3.Bucket(bucket)
key = bucket.new_key(obj)
key.set_contents_from_string('')
s3.put_object(Bucket=bucket, Key=obj, Body=b'')
for acl in module.params.get('permission'):
s3.put_object_acl(ACL=acl, Bucket=bucket, Key=obj)
module.exit_json(msg="Virtual directory %s created in bucket %s" % (obj, bucket.name), changed=True)
module.exit_json(msg="Virtual directory %s created in bucket %s" % (obj, bucket), changed=True)
except botocore.exceptions.ClientError as e:
module.fail_json(msg="Failed while creating object %s." % obj, exception=traceback.format_exc(), **camel_dict_to_snake_dict(e.response))

Expand Down
1 change: 1 addition & 0 deletions test/integration/targets/aws_s3/aliases
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
cloud/aws
posix/ci/cloud/group1/aws
8 changes: 0 additions & 8 deletions test/integration/targets/aws_s3/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,6 @@
- result.changed == True
- result.msg == "PUT operation complete"
# ============================================================
- name: wait a few seconds before continuing
pause:
seconds: 3
# ============================================================
- name: create a second temp file to download the object from the bucket
tempfile:
register: tmp2
Expand All @@ -96,10 +92,6 @@
that:
- file1stat.stat.checksum == file2stat.stat.checksum
# ============================================================
- name: wait a few seconds before continuing
pause:
seconds: 3
# ============================================================
- name: test geturl of the object
s3:
bucket: "{{ bucket.stdout }}"
Expand Down