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

ec2_ami is not deleting snapshots #39541

Closed
alan113696 opened this issue May 1, 2018 · 3 comments · Fixed by #39606
Closed

ec2_ami is not deleting snapshots #39541

alan113696 opened this issue May 1, 2018 · 3 comments · Fixed by #39606
Labels
affects_2.5 This issue/PR affects Ansible v2.5 aws bug This issue/PR relates to a bug. cloud module This issue/PR relates to a module. support:certified This issue/PR relates to certified code.

Comments

@alan113696
Copy link

ISSUE TYPE
  • Bug Report
COMPONENT NAME

ec2_ami

ANSIBLE VERSION
ansible 2.5.2
  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'/home/centos/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python2.7/site-packages/ansible
  executable location = /usr/bin/ansible
  python version = 2.7.5 (default, Aug  4 2017, 00:39:18) [GCC 4.8.5 20150623 (Red Hat 4.8.5-16)]
CONFIGURATION
OS / ENVIRONMENT

CentOS Linux release 7.4.1708 (Core)

SUMMARY

ec2_ami module does not appear to be deleting snapshots when using the "delete_snapshot=yes" parameter.

STEPS TO REPRODUCE
ansible -m ec2_ami -a "delete_snapshot=yes state=absent wait=yes image_id=ami-0ee6716f" localhost
EXPECTED RESULTS

Expected a response with non-empty "snapshots_deleted" list.

ACTUAL RESULTS
localhost | SUCCESS => {
    "changed": true, 
    "invocation": {
        "module_args": {
            "architecture": "x86_64", 
            "aws_access_key": null, 
            "aws_secret_key": null, 
            "billing_products": null, 
            "delete_snapshot": true, 
            "description": "", 
            "device_mapping": null, 
            "ec2_url": null, 
            "enhanced_networking": null, 
            "image_id": "ami-0ee6716f", 
            "image_location": null, 
            "instance_id": null, 
            "kernel_id": null, 
            "launch_permissions": null, 
            "name": null, 
            "no_reboot": false, 
            "profile": null, 
            "purge_tags": false, 
            "ramdisk_id": null, 
            "region": null, 
            "root_device_name": null, 
            "security_token": null, 
            "sriov_net_support": null, 
            "state": "absent", 
            "tags": null, 
            "validate_certs": true, 
            "virtualization_type": "hvm", 
            "wait": true, 
            "wait_timeout": 900
        }
    }, 
    "msg": "AMI deregister operation complete.", 
    "snapshots_deleted": []
}
@ansibot
Copy link
Contributor

ansibot commented May 1, 2018

Files identified in the description:

If these files are inaccurate, please update the component name section of the description or use the !component bot command.

click here for bot help

@ansibot
Copy link
Contributor

ansibot commented May 1, 2018

@ansibot ansibot added affects_2.5 This issue/PR affects Ansible v2.5 aws bug This issue/PR relates to a bug. cloud module This issue/PR relates to a module. needs_triage Needs a first human triage before being processed. support:certified This issue/PR relates to certified code. labels May 1, 2018
@alan113696
Copy link
Author

The following code might need to be revised:

snapshots = []
if 'BlockDeviceMappings' in image:
for mapping in image.get('BlockDeviceMappings'):
snapshot_id = mapping.get('SnapshotId')
if snapshot_id is not None:
snapshots.append(snapshot_id)

BlockDeviceMappings data structure looks like:

"BlockDeviceMappings": [
    {
           "DeviceName": "/dev/sda1", 
           "Ebs": {
               "Encrypted": false, 
               "DeleteOnTermination": true, 
               "VolumeType": "gp2", 
               "VolumeSize": 8, 
               "SnapshotId": "snap-03d5c521dd94a89bb"
           }
   }
],

Note that SnapshotId is nested within Ebs.

@jborean93 jborean93 removed the needs_triage Needs a first human triage before being processed. label May 3, 2018
@ansible ansible locked and limited conversation to collaborators May 7, 2019
reelsense added a commit to stationgroup/ansible-experiments that referenced this issue May 29, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.5 This issue/PR affects Ansible v2.5 aws bug This issue/PR relates to a bug. cloud module This issue/PR relates to a module. support:certified This issue/PR relates to certified code.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants