diff --git a/lib/ansible/modules/cloud/amazon/ec2_ami.py b/lib/ansible/modules/cloud/amazon/ec2_ami.py index 1b03ccd1083..84c30a9667e 100644 --- a/lib/ansible/modules/cloud/amazon/ec2_ami.py +++ b/lib/ansible/modules/cloud/amazon/ec2_ami.py @@ -496,7 +496,7 @@ def deregister_image(module, connection): snapshots = [] if 'BlockDeviceMappings' in image: for mapping in image.get('BlockDeviceMappings'): - snapshot_id = mapping.get('SnapshotId') + snapshot_id = mapping.get('Ebs', {}).get('SnapshotId') if snapshot_id is not None: snapshots.append(snapshot_id) diff --git a/test/integration/targets/ec2_ami/tasks/main.yml b/test/integration/targets/ec2_ami/tasks/main.yml index 66b73eb17cc..921417ca2d5 100644 --- a/test/integration/targets/ec2_ami/tasks/main.yml +++ b/test/integration/targets/ec2_ami/tasks/main.yml @@ -158,6 +158,7 @@ that: - "result.changed" - "'image_id' not in result" + - "result.snapshots_deleted" # ============================================================