# Cleaning up manual RDS snapshots

**URL:** <https://forum.ansible.com/t/cleaning-up-manual-rds-snapshots/28121>\
**Category:** Ansible Project\
**Created:** [July 22, 2018, 2:58pm UTC](https://forum.ansible.com/t/cleaning-up-manual-rds-snapshots/28121 "2018-07-22T14:58:29Z")\
**Posts on this page:** 3\
**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 22, 2018, 2:58pm UTC](https://forum.ansible.com/t/cleaning-up-manual-rds-snapshots/28121/1 "2018-07-22T14:58:29Z")

</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 }}”

---

<div class="post-metadata">

**Author:** ![Karl\_Auer](https://avatars.discourse-cdn.com/v4/letter/k/cc9497/32.png) [@Karl\_Auer](https://forum.ansible.com/u/Karl_Auer)\
**Post date:** [July 22, 2018, 11:27pm UTC](https://forum.ansible.com/t/cleaning-up-manual-rds-snapshots/28121/2 "2018-07-22T23:27:19Z")

</div>

You register “snapshot\_results”, but you reference “snapshots\_results”.

There may be other problems, but that’s why you are getting the undefined variable error.

Also, you should at some point make sure your code can handle the situation where there really are no snapshots to purge.

Regards, K.

---

<div class="post-metadata">

**Author:** ![willthames](https://avatars.discourse-cdn.com/v4/letter/w/8dc957/32.png) [@willthames](https://forum.ansible.com/u/willthames)\
**Post date:** [July 22, 2018, 11:54pm UTC](https://forum.ansible.com/t/cleaning-up-manual-rds-snapshots/28121/3 "2018-07-22T23:54:54Z")

</div>

You can use rds\_snapshot\_facts with Ansible 2.5.3

[http://willthames.github.io/2017/12/12/using-updated-modules-with-stable-ansible.html](http://willthames.github.io/2017/12/12/using-updated-modules-with-stable-ansible.html)
