Variable: register: ec2 is not properly parsed when used

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 :slight_smile:

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