Creating and deleting snapshots

Hi List,

I’m trying to create a playbook to create ec2 snapshots. That part woks:


  • hosts: tag_snapshot_yes
    gather_facts: true
    tasks:

Get a list of volume-id’s attached to the instance and put that list in

The variable named vollist

  • name: List volumes
    ec2_vol:
    instance: “{{ ec2_id }}”
    region: “{{ ec2_region }}”
    state: list
    register: vollist
    delegate_to: localhost

Simple snapshot of volume using volume_id from the vollist variable

  • name: Create snapshot
    ec2_snapshot:
    region: “{{ ec2_region }}”
    volume_id: “{{ item.id }}”
    description: “snapshot of {{ item.id }} from {{ ansible_hostname}}”
    snapshot_tags:
    Name: “{{ ansible_hostname}}”
    with_items: vollist.volumes
    delegate_to: localhost

This part works wonderfully!

But I don’t how to even start to manage the deletion of older snapshots.

Does anyone have suggestions? Or am i simply going about it the wrong way with Ansible?

Mark