I was just looking into how I might implement this and there's an interesting side effect of ec2_vol if a volume is already attached
Assuming you run ec2 and register the result as ec2, the following works:
- name: get root volume
action:
module: ec2_vol
instance: "{{ec2.instances[0].id}}"
device_name: '/dev/sda1'
region: ap-southeast-2
volume_size: 1
register: ec2_vol
(note that volume_size doesn't matter, it's ignored but the module fails without it - with an error message that can only be described as unhelpful!)
You get as a result:
ok: [127.0.0.1] => {"changed": false, "device": "/dev/sda1", "msg": "Volume mapping for /dev/sda1 already exists on instance i-834ab5bd", "volume_id": "vol-92cee996"}
And so you can use ec2_vol.volume_id as a resource id to pass to ec2_tag.
Will