title: Ansible: How to identify which EC2 instance is the current node to extract private IP
body: <p>I need to update some configuration, which includes a list of all the EC2 nodes in my cluster, but also each node's configuration needs to know its own EC2 public <strong>and</strong> private IP address.</p>
  
  <p>For the full list, I have the following:</p>
  
  <pre><code>- name: Gather EC2 facts on all nodes
    ec2_instance_facts:
      region: "{{ aws.region }}"
      filters:
        "tag:Type": nodeType
        "tag:Name": '{{ aws.ec2.nodes.name }}'
        "instance-state-name": running
    register: ec2_facts
  </code></pre>
  
  <p>Then gather all the IPs and add them to a group:</p>
  
  <pre><code>- name: Gather IPs for all hosts
    add_host: hostname={{ item.public_ip_address }} groups=allIpAddresses
    loop: "{{ ec2_facts.instances }}"
    when:
      - item.state.name == "running"
  </code></pre>
  
  <p>This groups variable is then used in another play and used to substitute out the values in an Ansible template:</p>
  
  <pre><code>- seeds: "{{ allIpAddresses[0] }},{{ allIpAddresses[1] }},{{ allIpAddresses[2] }},{{ allIpAddresses[3] }}"
  </code></pre>
  
  <p>However, I cannot seem to extract or identify which public and private IP is for the "current" host.</p>