# Cleaning up RDS Snapshots

**URL:** <https://forum.ansible.com/t/cleaning-up-rds-snapshots/28117>\
**Category:** Ansible Developer\
**Created:** [July 21, 2018, 5:29pm UTC](https://forum.ansible.com/t/cleaning-up-rds-snapshots/28117 "2018-07-21T17:29:19Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![tharun.kumarc09](https://avatars.discourse-cdn.com/v4/letter/t/dbc845/32.png) [@tharun.kumarc09](https://forum.ansible.com/u/tharun.kumarc09)\
**Post date:** [July 21, 2018, 5:29pm UTC](https://forum.ansible.com/t/cleaning-up-rds-snapshots/28117/1 "2018-07-21T17:29:19Z")

</div>

I am trying to cleanup the rds snapshots that are expired. We have expiration tag set with the 14 days from the day the snapshot created. These snapshots are created manually not automated snapshots.

Is there way we can leverage using ansible? I am currently using rds module but not able to get the snapshots facts. rds\_snapshot\_facts is available new version but we are using ansible 2.5.3.

Is shell scripting is only option available for this requirement?

This is how playbook currently looks like

- hosts: localhost  
connection: local  
gather\_facts: true  
vars:  
date\_fmt: “%Y-%m-%d”  
roles:
- name: rds-snapshot-cleanup

ansible\roles\rds-snapshot-cleanup\tasks\main.yml

- name: Set query string to find snapshots to purge  
set\_fact:  
snapshot\_query: “[? tags.expiration \< ‘{{ ansible\_date\_time.date|to\_datetime(date\_fmt) }}’]”

- name: Find all the rds snapshots  
rds:  
command: facts  
region: us-east-1  
register: snapshot\_results

- name: Find the snapshots to purge  
set\_fact:  
snapshots\_to\_purge: “{{ snapshots\_results.snapshots | json\_query( snapshot\_query ) }}”

- name: Purge snapshots  
rds:  
command: delete  
region: us-east-1  
snapshot: “{{item.snapshot\_name }}”  
with\_items: “{{snapshots\_to\_purge }}”

> **(attachments)**
>
> [rds-snapshot-cleanup.yml](https://forum.ansible.com/uploads/short-url/mDkNH0rsPAa9HJekxM2HWW0cu1H.yml) (135 Bytes)  
> [main.yml](https://forum.ansible.com/uploads/short-url/3jeLFyGGAkeIILUfiJHj0WWAuh0.yml) (571 Bytes)
