---
- 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