Skip to content

Commit

Permalink
[s3_bucket] Handle error paginating object versions when bucket does …
Browse files Browse the repository at this point in the history
…not exist (ansible#49396)
  • Loading branch information
s-hertel authored and samdoran committed Dec 4, 2018
1 parent a8fbfe1 commit a3e8917
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
3 changes: 3 additions & 0 deletions changelogs/fragments/s3_bucket_delete_nonexistent_bucket.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
bugfixes:
- Handle error paginating object versions when bucket does not exist (https://github.com/ansible/ansible/issues/49393)
13 changes: 8 additions & 5 deletions lib/ansible/modules/cloud/amazon/s3_bucket.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@
from ansible.module_utils.six.moves.urllib.parse import urlparse
from ansible.module_utils.six import string_types
from ansible.module_utils.basic import to_text
from ansible.module_utils.aws.core import AnsibleAWSModule
from ansible.module_utils.aws.core import AnsibleAWSModule, is_boto3_error_code
from ansible.module_utils.ec2 import compare_policies, ec2_argument_spec, boto3_tag_list_to_ansible_dict, ansible_dict_to_boto3_tag_list
from ansible.module_utils.ec2 import get_aws_connection_info, boto3_conn, AWSRetry

Expand Down Expand Up @@ -447,10 +447,13 @@ def paginated_list(s3_client, **pagination_params):


def paginated_versions_list(s3_client, **pagination_params):
pg = s3_client.get_paginator('list_object_versions')
for page in pg.paginate(**pagination_params):
# We have to merge the Versions and DeleteMarker lists here, as DeleteMarkers can still prevent a bucket deletion
yield [(data['Key'], data['VersionId']) for data in (page.get('Versions', []) + page.get('DeleteMarkers', []))]
try:
pg = s3_client.get_paginator('list_object_versions')
for page in pg.paginate(**pagination_params):
# We have to merge the Versions and DeleteMarker lists here, as DeleteMarkers can still prevent a bucket deletion
yield [(data['Key'], data['VersionId']) for data in (page.get('Versions', []) + page.get('DeleteMarkers', []))]
except is_boto3_error_code('NoSuchBucket'):
yield []


def destroy_bucket(s3_client, module):
Expand Down

0 comments on commit a3e8917

Please sign in to comment.