From 910bc892c66daa9d1d45061b55347e4655304484 Mon Sep 17 00:00:00 2001 From: Sloane Hertel Date: Thu, 3 May 2018 07:48:29 -0400 Subject: [PATCH] ec2_ami: Properly delete snapshots (#39606) --- lib/ansible/modules/cloud/amazon/ec2_ami.py | 2 +- test/integration/targets/ec2_ami/tasks/main.yml | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) 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" # ============================================================