# Get the id of the root EBS volume of an EC2 instance

**URL:** <https://forum.ansible.com/t/get-the-id-of-the-root-ebs-volume-of-an-ec2-instance/14997>\
**Category:** Ansible Project\
**Created:** [April 11, 2014, 9:59am UTC](https://forum.ansible.com/t/get-the-id-of-the-root-ebs-volume-of-an-ec2-instance/14997 "2014-04-11T09:59:09Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Christian\_Kaps](https://avatars.discourse-cdn.com/v4/letter/c/839c29/32.png) [@Christian\_Kaps](https://forum.ansible.com/u/Christian_Kaps)\
**Post date:** [April 11, 2014, 9:59am UTC](https://forum.ansible.com/t/get-the-id-of-the-root-ebs-volume-of-an-ec2-instance/14997/1 "2014-04-11T09:59:09Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![willthames](https://avatars.discourse-cdn.com/v4/letter/w/8dc957/32.png) [@willthames](https://forum.ansible.com/u/willthames)\
**Post date:** [April 13, 2014, 12:14am UTC](https://forum.ansible.com/t/get-the-id-of-the-root-ebs-volume-of-an-ec2-instance/14997/2 "2014-04-13T00:14:40Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![willthames](https://avatars.discourse-cdn.com/v4/letter/w/8dc957/32.png) [@willthames](https://forum.ansible.com/u/willthames)\
**Post date:** [April 13, 2014, 1:00am UTC](https://forum.ansible.com/t/get-the-id-of-the-root-ebs-volume-of-an-ec2-instance/14997/3 "2014-04-13T01:00:08Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Christian\_Kaps](https://avatars.discourse-cdn.com/v4/letter/c/839c29/32.png) [@Christian\_Kaps](https://forum.ansible.com/u/Christian_Kaps)\
**Post date:** [April 14, 2014, 10:25am UTC](https://forum.ansible.com/t/get-the-id-of-the-root-ebs-volume-of-an-ec2-instance/14997/4 "2014-04-14T10:25:49Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![willthames](https://avatars.discourse-cdn.com/v4/letter/w/8dc957/32.png) [@willthames](https://forum.ansible.com/u/willthames)\
**Post date:** [April 14, 2014, 12:52pm UTC](https://forum.ansible.com/t/get-the-id-of-the-root-ebs-volume-of-an-ec2-instance/14997/5 "2014-04-14T12:52:50Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Christian\_Kaps](https://avatars.discourse-cdn.com/v4/letter/c/839c29/32.png) [@Christian\_Kaps](https://forum.ansible.com/u/Christian_Kaps)\
**Post date:** [April 14, 2014, 3:39pm UTC](https://forum.ansible.com/t/get-the-id-of-the-root-ebs-volume-of-an-ec2-instance/14997/6 "2014-04-14T15:39:16Z")

</div>

Hi Will,

works like a charm.

Many thanks.  
Christian
