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

**URL:** <https://forum.ansible.com/t/variable-register-ec2-is-not-properly-parsed-when-used/17319>\
**Category:** Ansible Project\
**Created:** [January 20, 2015, 7:16am UTC](https://forum.ansible.com/t/variable-register-ec2-is-not-properly-parsed-when-used/17319 "2015-01-20T07:16:57Z")\
**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, 7:16am UTC](https://forum.ansible.com/t/variable-register-ec2-is-not-properly-parsed-when-used/17319/1 "2015-01-20T07:16:57Z")

</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  
&nbsp;&nbsp;&nbsp;local\_action:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;module: ec2  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;region: "{{ region }}"  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;key\_name: "key-dev"  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;instance\_type: "{{ ec2\_nat\_type }}"  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;image: "{{ ec2\_nat\_image }}"  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;wait: yes  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;group: "{{ rcrtx\_env }}\_sg\_nat"  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;instance\_tags:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Name: "{{ rcrtx\_env }}\_nat"  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;env: "{{ rcrtx\_env }}"  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;component: "nat"  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;vpc\_subnet\_id: "{{ item.id }}"  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;source\_dest\_check: no  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;monitoring: yes  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;exact\_count: 1  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;count\_tag:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;component: "nat"  
&nbsp;&nbsp;&nbsp;with\_items: vpc.subnets  
&nbsp;&nbsp;&nbsp;when: item.resource\_tags.Name == "{{ rcrtx\_env }}\_subnet\_public\_1a"  
&nbsp;&nbsp;&nbsp;register: ec2nat

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