# ec2 dict processing / volume provisioning

**URL:** <https://forum.ansible.com/t/ec2-dict-processing-volume-provisioning/20841>\
**Category:** Ansible Project\
**Created:** [March 11, 2016, 2:12pm UTC](https://forum.ansible.com/t/ec2-dict-processing-volume-provisioning/20841 "2016-03-11T14:12:25Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![hllmt67](https://avatars.discourse-cdn.com/v4/letter/h/ee7513/32.png) [@hllmt67](https://forum.ansible.com/u/hllmt67)\
**Post date:** [March 11, 2016, 2:12pm UTC](https://forum.ansible.com/t/ec2-dict-processing-volume-provisioning/20841/1 "2016-03-11T14:12:25Z")

</div>

Hi,

I am having issues with passing ec2 instance provisioning results to other tasks in a playbook.

I can launch instances, and then use "  
`register: ec2`

" to register a dictionary of the results. But I cannot seem to extract the instance id later.

Using debug I can see i get valid results:

> `  
> TASK [debug] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*
> 
> ok: [localhost] =\> {
> 
> “ec2.results”: [
> 
> {
> 
> “\_ansible\_no\_log”: false,
> 
> “changed”: true,
> 
> “instance\_ids”: [
> 
> “i-5bbc7cee”
> 
> ],
> 
> “instances”: [
> 
> {
> 
> “ami\_launch\_index”: “0”,
> 
> “architecture”: “x86\_64”,
> 
> “block\_device\_mapping”: {
> 
> “/dev/xvda”: {
> 
> “delete\_on\_termination”: true,
> 
> “status”: “attached”,
> 
> “volume\_id”: “vol-352da188”
> 
> }
> 
> },
> 
> “dns\_name”: “”,
> 
> “ebs\_optimized”: false,
> 
> “groups”: {
> 
> “sg-2b37d84f”: “mongo”
> 
> },
> 
> “hypervisor”: “xen”,
> 
> “id”: “i-5bbc7cee”,
> 
> “image\_id”: “ami-d1f482b1”,
> 
> “instance\_type”: “t2.micro”,
> 
> “kernel”: null,
> 
> “key\_name”: “keypair”,
> 
> “launch\_time”: “2016-03-11T13:33:09.000Z”,
> 
> “placement”: “us-west-1c”,
> 
> “private\_dns\_name”: “ip-172-x-x-x.us-west-1.compute.internal”,
> 
> “private\_ip”: “x.x.x.x”,
> 
> “public\_dns\_name”: “”,
> 
> “public\_ip”: null,
> 
> “ramdisk”: null,
> 
> “region”: “us-west-1”,
> 
> “root\_device\_name”: “/dev/xvda”,
> 
> “root\_device\_type”: “ebs”,
> 
> “state”: “running”,
> 
> “state\_code”: 16,
> 
> “tags”: {
> 
> “Name”: “mongo”,  
> },
> 
> “tenancy”: “default”,
> 
> “virtualization\_type”: “hvm”
> 
> }
> 
> ],
> 
> “invocation”: {
> 
> “module\_args”: {
> 
> “assign\_public\_ip”: false,
> 
> “aws\_access\_key”: “xxxxxxxxxxxxxxxxxxxxxx”,
> 
> “aws\_secret\_key”: “xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx”,
> 
> “count”: 1,
> 
> “count\_tag”: {
> 
> “volumes”: “data”
> 
> },
> 
> “ebs\_optimized”: false,
> 
> “ec2\_url”: null,
> 
> “exact\_count”: null,
> 
> “group”: [
> 
> “mongo”
> 
> ],
> 
> “group\_id”: null,
> 
> “id”: null,
> 
> “image”: “ami-d1f482b1”,
> 
> “instance\_ids”: null,
> 
> “instance\_profile\_name”: null,
> 
> “instance\_tags”: {
> 
> “Name”: “mongo”,
> 
> },
> 
> “instance\_type”: “t2.micro”,
> 
> “kernel”: null,
> 
> “key\_name”: “keypair”,
> 
> “monitoring”: false,
> 
> “network\_interfaces”: null,
> 
> “placement\_group”: null,
> 
> “private\_ip”: null,
> 
> “profile”: null,
> 
> “ramdisk”: null,
> 
> “region”: “us-west-1”,
> 
> “security\_token”: null,
> 
> “source\_dest\_check”: true,
> 
> “spot\_price”: null,
> 
> “spot\_type”: “one-time”,
> 
> “spot\_wait\_timeout”: 600,
> 
> “state”: “present”,
> 
> “tenancy”: “default”,
> 
> “termination\_protection”: false,
> 
> “user\_data”: null,
> 
> “validate\_certs”: true,
> 
> “volumes”: null,
> 
> “vpc\_subnet\_id”: “subnet-703aa229”,
> 
> “wait”: true,
> 
> “wait\_timeout”: 300,
> 
> “zone”: null
> 
> },
> 
> “module\_name”: “ec2”
> 
> },
> 
> “item”: “mongo”,
> 
> “tagged\_instances”:
> 
> }
> 
> ]
> 
> }
> 
> TASK [debug] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*
> 
> ok: [localhost] =\> {
> 
> “ec2.results.instances”: “VARIABLE IS NOT DEFINED!”
> 
> }
> 
> TASK [debug] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*
> 
> ok: [localhost] =\> {
> 
> “ec2.results.instance\_ids”: “VARIABLE IS NOT DEFINED!”
> 
> }
> 
> TASK [debug] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*
> 
> ok: [localhost] =\> {
> 
> “ec2.results.tagged\_instances”: “VARIABLE IS NOT DEFINED!”
> 
> }
> 
> TASK [debug] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*
> 
> ok: [localhost] =\> {
> 
> “ec2.results.0.instances.0.id”: “i-5bbc7cee”
> 
> }  
> `
> 
> The ec2 examples show using:

`

- ec2\_vol:  
instance: "{{ item.id }} "  
volume\_size: 5  
with\_items: ec2.instances  
register: ec2\_vol  
`

But that does not work, based on the above debugs, I tried:  
`

- ec2\_vol:

instance: “{{ item.id }}”

volume\_size: 10

with\_items: ec2.results.0.instances

register: ec2\_vol  
`

---

<div class="post-metadata">

**Author:** ![hllmt67](https://avatars.discourse-cdn.com/v4/letter/h/ee7513/32.png) [@hllmt67](https://forum.ansible.com/u/hllmt67)\
**Post date:** [March 11, 2016, 3:51pm UTC](https://forum.ansible.com/t/ec2-dict-processing-volume-provisioning/20841/2 "2016-03-11T15:51:29Z")

</div>

Well, after some more painful trial and error, and pissing Amazon off for sure, here’s a working solution:

I hope this saves someone some pain in the future.

`

- name: data volumes  
ec2\_vol:  
aws\_access\_key: “{{ key }}”  
aws\_secret\_key: “{{ secret }}”  
instance: “{{ item.instances.0.id }}”  
region: “{{item.instances.0.region}}”  
name: “{{ item.instances.0.tags.Name }}\_data”  
volume\_size: {{data\_vol\_size}}  
volume\_type: gp2  
device\_name: /dev/xvdb  
with\_items: ec2.results  
register: ec2\_vol

`
