I'd like to snapshot EC2 volumes only when needed. I couldn't find an
easy solution that didn't require calling out to boto or other tools.
If it exists, please ignore the following
I wanted to ask here
before opening a feature or pull request.
It could look like this:
- local_action:
module: ec2_snapshot
region: "{{ region }}"
instance_id: "{{ id }}"
device_name: "{{ device }}"
snapshot_tags:
SnapshotCreator: ansible
Host: "{{ server }}"
Device: "{{ device }}"
# new feature, using the snapshot_tags to determine current state
# currently it's "always"
state: present|absent|always
Does this make sense? Currently it's not available but could be
implemented in a backwards compatible way if the default state was
"always."
Thanks
Ted
Alternate suggestion for this new behavior: copy the ec2 module's count
options. It would add these options to ec2_snapshot.py:
...
exact_count:
version_added: "1.8"
description:
- An integer value which indicates how many snapshots that match the 'count_tag' parameter should be present. Snapshots are either created or terminated based on this value.
required: false
default: null
aliases:
count_tag:
version_added: "1.8"
description:
- Used with 'exact_count' to determine how many snapshots based on a specific tag criteria should be present.
required: false
default: null
aliases:
So when `exact_count` is omitted, things work like they do now, but if
it's specified, an `enforce_count()` function will be called.
Ted
...
Final suggestion 
boto has a nice `trim_snapshots()` method [1] that could simply be
called inline, given appropriate parameters from the ec2_snapshot
module. I could use that too, but it seems much less flexible than the
ec2 module's exact_count/count_tag approach.
Thanks!
Ted
[1] http://boto.readthedocs.org/en/latest/ref/ec2.html#boto.ec2.connection.EC2Connection.trim_snapshots
Hi Ted,
We’d be happy to consider a pull request to ansible/ansible-modules-core
(We would like to avoid cluttering up the tracker with feature requests as usually folks are unlikely to scratch itches of others)
ansible-devel list is the right forum to discuss what form this maybe should take.
Thanks!
We'd be happy to consider a pull request to ansible/ansible-modules-core
All right, as soon as I know what direction you prefer 
(We would like to avoid cluttering up the tracker with feature requests as
usually folks are unlikely to scratch itches of others)
That's fine, I already started developing one version, using
exact_count/count_tag. I just don't want to go too far and get the PR rejected.
ansible-devel list is the right forum to discuss what form this maybe
should take.
All right, following up there. I hope the original thread is clear from
what I quoted. My personal preference is to implement
exact_count/count_tag like the ec2 module does, but hooking into the
boto module's `trim_snapshots()` method is really effortless.
...ph, and maybe even then `trim_snapshots()` could be used through a
new ec2_snapshot_trim module. But that seems really trivial, since it's
just a call to python in the shell:
- shell:
cmd: python -c 'import boto; import json; ec2_conn = boto.connect_ec2(); ec2_conn.trim_snapshots(8, 7, 4, True)'
Let me know...
Thanks
Ted
I don’t really have this specific use case, so it’s hard for me to weigh in.
I’d see what others have to say that do have this particular question, and maybe it’s a new param or a new module, or maybe it’s a custom module that you use, etc.
I had this problem too. I didn't solve the cleaning up of old snapshots issue, but I added a feature to ec2_snapshot to only ceate a new snapshot if the last one is older than X minutes. My changes are in this PR if you're interested: https://github.com/ansible/ansible-modules-core/pull/76