Creating and deleting snapshots

29 views
Skip to first unread message

Mark Maas

unread,
Apr 22, 2015, 7:38:23 AM4/22/15
to ansible...@googlegroups.com
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
Reply all
Reply to author
Forward
0 new messages