# get ec2 instance id after ec2 creation

**URL:** <https://forum.ansible.com/t/get-ec2-instance-id-after-ec2-creation/20622>\
**Category:** Ansible Project\
**Created:** [February 19, 2016, 12:05am UTC](https://forum.ansible.com/t/get-ec2-instance-id-after-ec2-creation/20622 "2016-02-19T00:05:23Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Colin\_Byrne](https://avatars.discourse-cdn.com/v4/letter/c/ecd19e/32.png) [@Colin\_Byrne](https://forum.ansible.com/u/Colin_Byrne)\
**Post date:** [February 19, 2016, 12:05am UTC](https://forum.ansible.com/t/get-ec2-instance-id-after-ec2-creation/20622/1 "2016-02-19T00:05:23Z")

</div>

Hey, so I feel like I am following all the tutorials… but I can’t seem to get the instance id after I create and instance with the ec2 module, to use for other modules, like the ec2\_vol module, which depends on the ec2 instance id to attach it to the correct instance. I am not sure if I am missing some underlying concept, or missing a variable or missing something else. Here are my ec2 and ec2\_vol modules:

`

---

<div class="post-metadata">

**Author:** ![alexey.vazhnov](https://avatars.discourse-cdn.com/v4/letter/a/b487fb/32.png) [@alexey.vazhnov](https://forum.ansible.com/u/alexey.vazhnov)\
**Post date:** [February 19, 2016, 9:04am UTC](https://forum.ansible.com/t/get-ec2-instance-id-after-ec2-creation/20622/2 "2016-02-19T09:04:41Z")

</div>

It is strange, look like all must to work. I don’t understand why you received “undefined attribute”.  
Try to add after first task:

`

- debug: var=ec2  
`

---

<div class="post-metadata">

**Author:** ![Colin\_Byrne](https://avatars.discourse-cdn.com/v4/letter/c/ecd19e/32.png) [@Colin\_Byrne](https://forum.ansible.com/u/Colin_Byrne)\
**Post date:** [February 19, 2016, 6:32pm UTC](https://forum.ansible.com/t/get-ec2-instance-id-after-ec2-creation/20622/3 "2016-02-19T18:32:33Z")

</div>

hey, thanks, thats a good idea. Here is my output. Instances is clearly empty… I am using private vpc subnet instances… Do you think that may be why they aren’t loading?

my debug output is:  
`

ok: [localhost] =\> {

“ec2”: {

“changed”: false,

“msg”: “All items completed”,

“results”: [

{

“\_ansible\_no\_log”: false,

“changed”: false,

“instance\_ids”: null,

“instances”: ,

“invocation”: {

“module\_args”: {

“assign\_public\_ip”: false,

“aws\_access\_key”: null,

“aws\_secret\_key”: null,

“count”: 1,

“count\_tag”: {

“Name”: “s-test”

},

“ebs\_optimized”: false,

“ec2\_url”: null,

“exact\_count”: 1,

“group”: null,

“group\_id”: [

“sg-81398ee4”,

“sg-a6398ec3”

],

“id”: null,

“image”: “ami-06116566”,

“instance\_ids”: null,

“instance\_profile\_name”: null,

“instance\_tags”: {

“Name”: “s-test”,

“Type”: “staging”

},

“instance\_type”: “t2.medium”,

“kernel”: null,

“key\_name”: “ansible\_provisioning”,

“monitoring”: false,

“network\_interfaces”: null,

“placement\_group”: null,

“private\_ip”: “10.101.1.33”,

“profile”: null,

“ramdisk”: null,

“region”: “us-east-1”,

“security\_token”: null,

“source\_dest\_check”: true,

“spot\_launch\_group”: null,

“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-819f45cd8”,

“wait”: true,

“wait\_timeout”: 300,

“zone”: null

},

“module\_name”: “ec2”

},

“item”: [

{

“environment”: “staging”

},

{

“name”: “s-test”,

“private\_ip”: “10.101.1.33”,

“type”: “app”

}

],

“tagged\_instances”: [

{

“ami\_launch\_index”: “0”,

“architecture”: “x86\_64”,

“block\_device\_mapping”: {

“/dev/sda1”: {

“delete\_on\_termination”: true,

“status”: “attached”,

“volume\_id”: “vol-c14a1569”

}

},

“dns\_name”: “”,

“ebs\_optimized”: false,

“groups”: {

“sg-81398ee4”: “ssh”,

“sg-a6398ec3”: “default”

},

“hypervisor”: “xen”,

“id”: “i-11eeg8a3”,

“image\_id”: “ami-06116566”,

“instance\_type”: “t2.medium”,

“kernel”: null,

“key\_name”: “ansible\_provisioning”,

“launch\_time”: “2016-02-03T22:47:37.000Z”,

“placement”: “us-west-1a”,

“private\_dns\_name”: “ip-10-101-1-33.us-west-1.compute.internal”,

“private\_ip”: “10.101.1.33”,

“public\_dns\_name”: “”,

“public\_ip”: null,

“ramdisk”: null,

“region”: “us-west-1”,

“root\_device\_name”: “/dev/sda1”,

“root\_device\_type”: “ebs”,

“state”: “running”,

“state\_code”: 16,

“tags”: {

“Name”: “s-colin”,

“Type”: “integ”

},

“tenancy”: “default”,

“virtualization\_type”: “hvm”

}

]

}

]

}

}

`

---

<div class="post-metadata">

**Author:** ![Colin\_Byrne](https://avatars.discourse-cdn.com/v4/letter/c/ecd19e/32.png) [@Colin\_Byrne](https://forum.ansible.com/u/Colin_Byrne)\
**Post date:** [February 19, 2016, 6:57pm UTC](https://forum.ansible.com/t/get-ec2-instance-id-after-ec2-creation/20622/4 "2016-02-19T18:57:03Z")

</div>

I just confirmed that having only a private ip is NOT the reason for the failure here. I haven’t yet tested wether being under a vpc subnet is the reason, which I would doubt…
