# ec2\_vol module return value

**URL:** <https://forum.ansible.com/t/ec2-vol-module-return-value/13495>\
**Category:** Ansible Project\
**Tags:** aws\
**Created:** [September 17, 2013, 2:31pm UTC](https://forum.ansible.com/t/ec2-vol-module-return-value/13495 "2013-09-17T14:31:57Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![cpatanaik](https://avatars.discourse-cdn.com/v4/letter/c/cdc98d/32.png) [@cpatanaik](https://forum.ansible.com/u/cpatanaik)\
**Post date:** [September 17, 2013, 2:31pm UTC](https://forum.ansible.com/t/ec2-vol-module-return-value/13495/1 "2013-09-17T14:31:57Z")

</div>

Hi,

I want to register the return value of ec2\_vol module so that I can retrieve the volume id and use it later.

My playbook is -

- name: Add volume  
local\_action: ec2\_vol instance={{item.id}} volume\_size=5 aws\_access\_key={{aa\_key}} aws\_secret\_key={{as\_key}} region={{region}}  
with\_items: ec2.instances  
register: ec2\_vol  
ignore\_errors: yes

- name: Stop instance  
local\_action: command aws ec2 stop-instances --profile=test --instance-id={{item.id}}  
with\_items: ec2.instances  
ignore\_errors: yes

- name: Detach volume from instance  
local\_action: command aws ec2 detach-volume --profile=test --volume-id={{item.Y}} \<--------------------------------------------------------  
with\_items: ec2\_vol.X \<----------------------------------------------------------------------------------------------------------------------------------------------------  
ignore\_errors: yes

What should I use in place of X and Y to get the volume ids of newly created volumes…??

---

<div class="post-metadata">

**Author:** ![Lester\_Wade](https://avatars.discourse-cdn.com/v4/letter/l/97f17d/32.png) [@Lester\_Wade](https://forum.ansible.com/u/Lester_Wade)\
**Post date:** [September 17, 2013, 3:04pm UTC](https://forum.ansible.com/t/ec2-vol-module-return-value/13495/2 "2013-09-17T15:04:09Z")

</div>

Hi,

I think just volume\_id, so ec2\_vol.volume\_id as the with\_items.

Kind Regards,

Lester

---

<div class="post-metadata">

**Author:** ![cpatanaik](https://avatars.discourse-cdn.com/v4/letter/c/cdc98d/32.png) [@cpatanaik](https://forum.ansible.com/u/cpatanaik)\
**Post date:** [September 17, 2013, 3:47pm UTC](https://forum.ansible.com/t/ec2-vol-module-return-value/13495/3 "2013-09-17T15:47:47Z")

</div>

Hi lester,

I tried but it didn’t work. Below is my playbook-

- name: Detach volume from instance  
local\_action: command aws ec2 detach-volume --profile=test --volume-id={{item}}  
with\_items: ec2\_vol.volume\_id  
ignore\_errors: yes

I get an error as shown below -

TASK: [Detach volume from instance] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
failed: [localhost] =\> (item=ec2\_vol.volume\_id) =\> {“changed”: true, “cmd”: [“aws”, “ec2”, “detach-volume”, “–profile=test”, “–volume-id=ec2\_vol.volume\_id”], “delta”: “0:00:00.756544”, “end”: “2013-09-17 15:38:39.200170”, “item”: “ec2\_vol.volume\_id”, “rc”: 255, “start”: “2013-09-17 15:38:38.443626”}  
stderr: A client error (InvalidVolumeID.Malformed) occurred: Invalid id: “ec2\_vol.volume\_id” (expecting “vol-…”)  
…ignoring

I saw the code for ec2\_vol and it uses boto’s create\_volume() module. But in boto’s documentation([http://docs.pythonboto.org/en/latest/ref/ec2.html#module-boto.ec2.volume](http://docs.pythonboto.org/en/latest/ref/ec2.html#module-boto.ec2.volume)), it says that id represents volume\_id.

Any help is appreciated.

Thanks,
