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

On 14 Apr 2014, at 20:25, Christian Kaps <[email protected]> wrote:

> Hi Will,
> 
> Thanks for your answer.
> 
> I would like to create a tag for the root volume. So for my use case the ec2 
> module should return the IDs and the device names of the attached volumes 
> after instance creation.
> 
> Should I create a future request and point to this thread?
> 
> Thanks,
> Christian
> 
> Am Sonntag, 13. April 2014 03:00:08 UTC+2 schrieb Will Thames:
> Had a quick look at this in more detail.
> 
> Neither the ec2 nor the ec2_facts module expose this information. It is 
> available but in particular adding it to ec2_facts module would require 
> fundamental changes (as currently the ec2_facts module gets all of its 
> information from logging onto the box and reading the metadata, whereas this 
> information would only be available through talking to the API - see 
> http://stackoverflow.com/questions/5251057/using-boto-to-find-to-which-device-and-ebs-volume-is-mounted).
>  I'm not adverse to such a change but making it optional and non-breaking for 
> other users of the module is probably the challenge. 
> 
> Returning the value from the ec2 module is probably quite straightforward, on 
> the other hand.
> 
> Will
> 
> On 13 Apr 2014, at 10:14, Will Thames <[email protected]> wrote:
> 
>> Hi Christian,
>> How would you like to obtain the information - at instance creation time or 
>> at an arbitrary point in time later? (i.e. do you want to be able to get the 
>> instance ID as a value returned by the ec2 module, or from ec2_facts?)
>> 
>> Will
>> 
>> On Friday, April 11, 2014 7:59:09 PM UTC+10, Christian Kaps wrote:
>> Hi,
>> 
>> is there any possibility to get the id of the root EBS volume of a newly 
>> created EC2 instance? I cannot find any documentation about it?
>> 
>> Thanks,
>> Christian
>> 
>> -- 
>> You received this message because you are subscribed to a topic in the 
>> Google Groups "Ansible Project" group.
>> To unsubscribe from this topic, visit 
>> https://groups.google.com/d/topic/ansible-project/0vqsUHrn2AU/unsubscribe.
>> To unsubscribe from this group and all its topics, send an email to 
>> [email protected].
>> To post to this group, send email to [email protected].
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/ansible-project/ef9babed-2fb5-420d-b927-699bdc917673%40googlegroups.com.
>> For more options, visit https://groups.google.com/d/optout.
> 
> 
> -- 
> You received this message because you are subscribed to a topic in the Google 
> Groups "Ansible Project" group.
> To unsubscribe from this topic, visit 
> https://groups.google.com/d/topic/ansible-project/0vqsUHrn2AU/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to 
> [email protected].
> To post to this group, send email to [email protected].
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/ansible-project/f7e5c6c7-c2be-41da-acd8-a3fda19021dd%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/21F5F4C5-554E-40EC-AED9-14870E69AEF7%40thames.id.au.
For more options, visit https://groups.google.com/d/optout.

Reply via email to