# Using ec2\_vol with dynamic inventory

**URL:** <https://forum.ansible.com/t/using-ec2-vol-with-dynamic-inventory/22078>\
**Category:** Ansible Project\
**Created:** [July 21, 2016, 4:50pm UTC](https://forum.ansible.com/t/using-ec2-vol-with-dynamic-inventory/22078 "2016-07-21T16:50:26Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Max\_Leon1](https://avatars.discourse-cdn.com/v4/letter/m/ecd19e/32.png) [@Max\_Leon1](https://forum.ansible.com/u/Max_Leon1)\
**Post date:** [July 21, 2016, 4:50pm UTC](https://forum.ansible.com/t/using-ec2-vol-with-dynamic-inventory/22078/1 "2016-07-21T16:50:26Z")

</div>

Hi,  
I’m trying to create a playbook that will attach a volume to the specified instances and install casssandra as a cluster.

I have almost everything worked out but the ec2\_vol part.

# tasks file for cassandra

- name: gather ec2 facts  
action: ec2\_facts  
register: ec2\_facts

- debug: var=ec2\_facts

- name: Add volume for cassandra nodes  
local\_action:  
module: ec2\_vol  
instance: “{{ ansible\_ec2\_instance\_id }}”  
volume\_size: 50  
volume\_type: gp2  
region: us-east-1  
device\_name: /dev/xvdb

With that in mind I can see the ec2\_facts of the tagged instances that I’m going to use in the cluster but when executed it doesn’t recognized the ansible\_ec2\_instance\_id variable that I can actually see when running the ec2\_facts.

Any idea why?

Thank you.

---

<div class="post-metadata">

**Author:** ![jdelaporte](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/jdelaporte/32/366_2.png) [@jdelaporte](https://forum.ansible.com/u/jdelaporte)\
**Post date:** [July 21, 2016, 7:23pm UTC](https://forum.ansible.com/t/using-ec2-vol-with-dynamic-inventory/22078/2 "2016-07-21T19:23:36Z")

</div>

Hi Max,

Are you running this playbook with the ec2 instance as the remote target?

You are missing the reference to the registered fact, I think:

- name: gather ec2 facts  
action: ec2\_facts  
register: ec2\_facts

- debug: var=ec2\_facts

- name: Add volume for cassandra nodes  
local\_action:  
module: ec2\_vol  
instance: “{{ \*\*ec2\_facts.\*\*ansible\_ec2\_instance\_id }}”  
volume\_size: 50  
volume\_type: gp2  
region: us-east-1  
device\_name: /dev/xvdb

I haven’t used the ec2\_facts module yet myself, however, since I usually provision and register facts from the ec2 module, so I might be wrong.

Joanna

---

<div class="post-metadata">

**Author:** ![Max\_Leon](https://avatars.discourse-cdn.com/v4/letter/m/7bcc69/32.png) [@Max\_Leon](https://forum.ansible.com/u/Max_Leon)\
**Post date:** [July 21, 2016, 10:53pm UTC](https://forum.ansible.com/t/using-ec2-vol-with-dynamic-inventory/22078/3 "2016-07-21T22:53:34Z")

</div>

Hi Joanna,

Thanks for your post, I just tried your suggestion but still isn’t working. But you pointed me in the right direction. I was running ec2\_facts as a local action which was incorrect and using a tripple debug flag I noticed that aws\_access\_key and aws\_secret\_key were null, seems kind of dump having to set them up as variables for ec2\_vol to work, but after doing that but it worked, bellow how I end up doing it
