# Variable: register: ec2 is not properly parsed when used

**URL:** <https://forum.ansible.com/t/variable-register-ec2-is-not-properly-parsed-when-used/17323>\
**Category:** Ansible Project\
**Created:** [January 20, 2015, 8:39am UTC](https://forum.ansible.com/t/variable-register-ec2-is-not-properly-parsed-when-used/17323 "2015-01-20T08:39:29Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ivan\_Dimitrov](https://avatars.discourse-cdn.com/v4/letter/i/8dc957/32.png) [@Ivan\_Dimitrov](https://forum.ansible.com/u/Ivan_Dimitrov)\
**Post date:** [January 20, 2015, 8:39am UTC](https://forum.ansible.com/t/variable-register-ec2-is-not-properly-parsed-when-used/17323/1 "2015-01-20T08:39:29Z")

</div>

Hello Guys,

This is the first time I write to the group, so please bare with me if I miss something or my English is bad.

I want to create ec2 instances and use the output of the ec2 module as input for other tasks, like the description in the documentation. Unfortunately, unlike the documentation I have a problem using the ec2 variable that I register. The documentation states that to get the instance ID I need to do ec2.instanses.id, but actually I had to dive deeper and manually set it to ec2.results[0].instances[0].id. This is very error prone because the underlaying json returned by the ec2 module constantly changes the location of ec2.results and/or instances.

Am I doing something wrong? I really want to use the simple format ec2.instances.id

Here is the current example

- name: Provision NAT instance  
local\_action:  
module: ec2  
region: “{{ region }}”  
key\_name: “key-dev”  
instance\_type: “{{ ec2\_nat\_type }}”  
image: “{{ ec2\_nat\_image }}”  
wait: yes  
group: “{{ rcrtx\_env }}\_sg\_nat”  
instance\_tags:  
Name: “{{ rcrtx\_env }}\_nat”  
env: “{{ rcrtx\_env }}”  
component: “nat”  
vpc\_subnet\_id: “{{ item.id }}”  
source\_dest\_check: no  
monitoring: yes  
exact\_count: 1  
count\_tag:  
component: “nat”  
with\_items: vpc.subnets  
when: item.resource\_tags.Name == “{{ rcrtx\_env }}\_subnet\_public\_1a”  
register: ec2nat

- name: Associate new EIP for the NAT instance  
tags: eip  
local\_action:  
module: ec2\_eip  
in\_vpc: yes  
region: “{{ region }}”  
instance\_id: “{{ ec2nat.results[0].instances[0].id }}”  
when: ec2nat.results[0].instances[0].id is defined
