<p dir="auto">*** THIS IS A DUPLICATE BUG REPORT ***</p>
<p dir="auto">I am submitting it because the last one has had "please reopen" for a year but I don't think it's being picked up somehow.</p>
<p dir="auto">*** ORIGINAL REPORT ***</p>
<p dir="auto"><a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="135180860" data-permission-text="Title is private" data-url="https://github.com/ansible/ansible/issues/14593" data-hovercard-type="issue" data-hovercard-url="/ansible/ansible/issues/14593/hovercard" href="https://github.com/ansible/ansible/issues/14593">#14593</a></p>
<p dir="auto">*** ACTUAL REPORT ***</p>
<h5 dir="auto">Issue Type:</h5>
<p dir="auto">Bug Report</p>
<h5 dir="auto">COMPONENT NAME</h5>
<p dir="auto">ec2 module</p>
<h5 dir="auto">ANSIBLE VERSION</h5>
<p dir="auto">ansible 2.1.0 (devel <a class="commit-link" data-hovercard-type="commit" data-hovercard-url="https://github.com/ansible/ansible/commit/6a62ad6c4b4dd8c2ed3402a1c08af13847574bb8/hovercard" href="https://github.com/ansible/ansible/commit/6a62ad6c4b4dd8c2ed3402a1c08af13847574bb8"><tt>6a62ad6</tt></a>) last updated 2016/02/01 13:04:11 (GMT -700)<br>
lib/ansible/modules/core: (detached HEAD <a class="commit-link" data-hovercard-type="commit" data-hovercard-url="https://github.com/ansible/ansible/commit/93d02189f6dcfa0578a0fac0fb1f289369ac13a5/hovercard" href="https://github.com/ansible/ansible/commit/93d02189f6dcfa0578a0fac0fb1f289369ac13a5"><tt>93d0218</tt></a>) last updated 2016/02/01 13:04:24 (GMT -700)<br>
lib/ansible/modules/extras: (detached HEAD <a class="commit-link" data-hovercard-type="commit" data-hovercard-url="https://github.com/ansible/ansible/commit/fff5ae6994fbe64d45323bc1d11f6103e211f524/hovercard" href="https://github.com/ansible/ansible/commit/fff5ae6994fbe64d45323bc1d11f6103e211f524"><tt>fff5ae6</tt></a>) last updated 2016/02/01 13:04:31 (GMT -700)<br>
config file = /etc/ansible/ansible.cfg<br>
configured module search path = Default w/o overrides</p>
<h5 dir="auto">CONFIGURATION</h5>
<p dir="auto">no significant changes,<br>
scp_if_ssh=True</p>
<h5 dir="auto">ENVIRONMENT</h5>
<p dir="auto">N/A</p>
<h5 dir="auto">SUMMARY</h5>
<p dir="auto">After running the ec2 module and registering the ec2 variable, then looping over the ec2.results I am only able to access item.instances when creating a new instance. If it the instance is already created, ec2.results.instances returns as an empty set, and therefore the task breaks on that iteration. I instead have had to access the instance id by {{ item.tagged_instances.0.id }} which consistently holds the instance id wether the instances is being created or wether it already exists, but this isn't entirely reliable either as (I believe) it is only populated if the instance is tagged.</p>
<p dir="auto">Additionally, the nesting of these variables is different than what is described in the documentation on <a href="http://docs.ansible.com/ansible/ec2_vol_module.html" rel="nofollow">http://docs.ansible.com/ansible/ec2_vol_module.html</a>, which states that you should be able to access the instances simply by ec2.instances. Did this change with 2.0?</p>
<p dir="auto">Steps To Reproduce:</p>
<p dir="auto">Here is my list I am iterating over:</p>
<p dir="auto">server_environments:</p>
<ul dir="auto">
<li>environment: production<br>
servers:
<ul dir="auto">
<li>{ type: bastion, name: j-bastion, private_ip: 10.1.1.250 }</li>
<li>{ type: app, name: j-delete, private_ip: 10.1.1.106 }<br>
Here is my playbook:</li>
</ul>
</li>
</ul>
<hr>
<ul dir="auto">
<li>hosts: localhost<br>
gather_facts: False<br>
roles:
<ul dir="auto">
<li>provision_ec2<br>
Here is my provision_ec2 role:</li>
</ul>
</li>
</ul>
<hr>
<ul dir="auto">
<li>name: Launch instances based on server list<br>
ec2:<br>
key_name: ansible_provisioning.txt<br>
group_id: 'sg-81398ee4', 'sg-a6398ec3'<br>
instance_type: t2.medium<br>
image: ami-06116566<br>
termination_protection: yes<br>
wait: true<br>
region: us-west-2<br>
instance_tags:<br>
Type: "{{ item.0.environment }}"<br>
Name: "{{ item.1.name }}"<br>
exact_count: 1<br>
count_tag:<br>
Name: "{{ item.1.name }}"<br>
vpc_subnet_id: subnet-819f7gd2<br>
assign_public_ip: yes<br>
private_ip: "{{ item.1.private_ip }}"<br>
register: ec2<br>
with_subelements:
<ul dir="auto">
<li>server_environments</li>
<li>servers</li>
</ul>
</li>
</ul>
<h1 dir="auto">Use this to see what is contained in the ec2 variable</h1>
<ul dir="auto">
<li>
<p dir="auto">name: debug...<br>
debug: var=ec2.results<br>
This DID NOT work (shown as acceptable int the documentation)</p>
</li>
<li>
<p dir="auto">name: Attach volumes to created instances<br>
ec2_vol:<br>
instance: "{{ item.id }}"<br>
device_name: /dev/xvdb<br>
volume_size: 200<br>
volume_type: gp2<br>
iops: 600<br>
with_items: ec2.instances<br>
register: ec2_vol<br>
This DID work but is not reliable</p>
</li>
<li>
<p dir="auto">name: Attach volumes to created instances<br>
ec2_vol:<br>
instance: "{{ item.tagged_instances.0.id }}"<br>
device_name: /dev/xvdb<br>
volume_size: 200<br>
volume_type: gp2<br>
iops: 600<br>
with_items: ec2.results<br>
register: ec2_vol<br>
Here is a gist with my debug output which shows the abnormal nesting and the instance.id only being populated for the newly created instance</p>
</li>
</ul>
<p dir="auto">Expected/Actual Results:</p>
<p dir="auto">I expected there to be an ec2.instancesproperty, not an ec2.results property and I expected the ec2.results.instances property to contain ids for all instances in my server list, not just the newly created ones.</p>
<p dir="auto">Please close this one, and reopen that one.</p>
<h5 dir="auto">Issue Type: Bug Report</h5>
<h5 dir="auto">Ansible Version:</h5>
<p dir="auto">ansible 1.6.6 linux (centos 6.5)<br>
ansible 1.6.10 OpenBSD 5.5 (on OpenBSD tested also on ansible 1.6.6. Used newer ansible release to show it still happens)</p>
<h5 dir="auto">Environment:</h5>
<ul dir="auto">
<li>ansible is run local to the server in each instances</li>
<li>host: Centos 6.5 and OpenBSD 5.5</li>
</ul>
<h5 dir="auto">Summary:</h5>
<p dir="auto">An OpenBSD system not able to assign retrieved fact for ansible_interface.ipv4.address to variable.</p>
<h5 dir="auto">Steps To Reproduce:</h5>
<h4 dir="auto">create play (Centos 6.5)</h4>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="
---
# test.yml

- hosts: localhost
  connection: local
  remote_user: gregm
#  sudo: yes

  tasks:
  # name: address (frrebsd and openbsd replace with em0 ans nic)
  - debug: msg={{ ansible_eth0.ipv4.address }}
  - debug: msg={{ ansible_default_ipv4.address }}

# EOF"><pre class="notranslate"><code class="notranslate">
---
# test.yml

- hosts: localhost
  connection: local
  remote_user: gregm
#  sudo: yes

  tasks:
  # name: address (frrebsd and openbsd replace with em0 ans nic)
  - debug: msg={{ ansible_eth0.ipv4.address }}
  - debug: msg={{ ansible_default_ipv4.address }}

# EOF
</code></pre></div>
<h4 dir="auto">create paly (OpenBSD 5.5)</h4>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="
---
# test.yml

- hosts: localhost
  connection: local
  remote_user: gregm
#  sudo: yes

  tasks:
    # name: address
    - debug: msg={{ ansible_alc0.ipv4.address }}
    - debug: msg={{ ansible_default_ipv4.address }}"><pre class="notranslate"><code class="notranslate">
---
# test.yml

- hosts: localhost
  connection: local
  remote_user: gregm
#  sudo: yes

  tasks:
    # name: address
    - debug: msg={{ ansible_alc0.ipv4.address }}
    - debug: msg={{ ansible_default_ipv4.address }}
</code></pre></div>
<h5 dir="auto">Expected Results:</h5>
<ul dir="auto">
<li>I would expect the same results on OpenBSD as the one on Centos 6.5. I tested it also with ansible 1.6.6 on OpenBSD and the same happened.</li>
</ul>
<h4 dir="auto">for reference, I include collected facts from the Centos 6.5 host:</h4>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="    &quot;ansible_eth0&quot;: {
        &quot;active&quot;: true,
        &quot;device&quot;: &quot;eth0&quot;,
        &quot;ipv4&quot;: {
            &quot;address&quot;: &quot;192.168.0.44&quot;,
            &quot;netmask&quot;: &quot;255.255.255.0&quot;,
            &quot;network&quot;: &quot;192.168.0.0&quot;
        },
        &quot;ipv6&quot;: [
            {
                &quot;address&quot;: &quot;fe80::20c:29ff:fefd:f56c&quot;,
                &quot;prefix&quot;: &quot;64&quot;,
                &quot;scope&quot;: &quot;link&quot;
            }
        ],
        &quot;macaddress&quot;: &quot;00:0c:29:fd:f5:6c&quot;,
        &quot;module&quot;: &quot;e1000&quot;,
        &quot;mtu&quot;: 1500,
        &quot;promisc&quot;: false,
        &quot;type&quot;: &quot;ether&quot;"><pre class="notranslate"><code class="notranslate">    "ansible_eth0": {
        "active": true,
        "device": "eth0",
        "ipv4": {
            "address": "192.168.0.44",
            "netmask": "255.255.255.0",
            "network": "192.168.0.0"
        },
        "ipv6": [
            {
                "address": "fe80::20c:29ff:fefd:f56c",
                "prefix": "64",
                "scope": "link"
            }
        ],
        "macaddress": "00:0c:29:fd:f5:6c",
        "module": "e1000",
        "mtu": 1500,
        "promisc": false,
        "type": "ether"
</code></pre></div>
<h4 dir="auto">Centos 6.5 results:</h4>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="PLAY [localhost] **************************************************************

GATHERING FACTS ***************************************************************
ok: [localhost]

TASK: [debug msg={{ansible_eth0.ipv4.address}}] *******************************
ok: [localhost] =&gt; {
    &quot;msg&quot;: &quot;192.168.0.44&quot;
}

TASK: [debug msg={{ansible_default_ipv4.address}}] ****************************
ok: [localhost] =&gt; {
    &quot;msg&quot;: &quot;192.168.0.44&quot;
}

PLAY RECAP ********************************************************************
localhost                  : ok=3    changed=0    unreachable=0    failed=0"><pre class="notranslate"><code class="notranslate">PLAY [localhost] **************************************************************

GATHERING FACTS ***************************************************************
ok: [localhost]

TASK: [debug msg={{ansible_eth0.ipv4.address}}] *******************************
ok: [localhost] =&gt; {
    "msg": "192.168.0.44"
}

TASK: [debug msg={{ansible_default_ipv4.address}}] ****************************
ok: [localhost] =&gt; {
    "msg": "192.168.0.44"
}

PLAY RECAP ********************************************************************
localhost                  : ok=3    changed=0    unreachable=0    failed=0
</code></pre></div>
<h5 dir="auto">Actual Results:</h5>
<h4 dir="auto">For referance, I included fact collected from the OpenBSD 5.5 host</h4>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="localhost | success &gt;&gt; {
    &quot;ansible_facts&quot;: {
        &quot;ansible_alc0&quot;: {
            &quot;device&quot;: &quot;alc0&quot;,
            &quot;flags&quot;: [
                &quot;UP&quot;,
                &quot;BROADCAST&quot;,
                &quot;RUNNING&quot;,
                &quot;SIMPLEX&quot;,
                &quot;MULTICAST&quot;
            ],
            &quot;ipv4&quot;: [
                {
                    &quot;address&quot;: &quot;192.168.16.95&quot;,
                    &quot;broadcast&quot;: &quot;192.168.16.255&quot;,
                    &quot;netmask&quot;: &quot;255.255.255.0&quot;,
                    &quot;network&quot;: &quot;192.168.16.0&quot;
                }
            ],
            &quot;ipv6&quot;: [
                {
                    &quot;address&quot;: &quot;fe80::224:1dff:fe56:e3f4%alc0&quot;,
                    &quot;prefix&quot;: &quot;64&quot;,
                    &quot;scope&quot;: &quot;0x1&quot;
                }
            ],"><pre class="notranslate"><code class="notranslate">localhost | success &gt;&gt; {
    "ansible_facts": {
        "ansible_alc0": {
            "device": "alc0",
            "flags": [
                "UP",
                "BROADCAST",
                "RUNNING",
                "SIMPLEX",
                "MULTICAST"
            ],
            "ipv4": [
                {
                    "address": "192.168.16.95",
                    "broadcast": "192.168.16.255",
                    "netmask": "255.255.255.0",
                    "network": "192.168.16.0"
                }
            ],
            "ipv6": [
                {
                    "address": "fe80::224:1dff:fe56:e3f4%alc0",
                    "prefix": "64",
                    "scope": "0x1"
                }
            ],
</code></pre></div>
<h4 dir="auto">OpenBSD 5.5 results</h4>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="PLAY [localhost] **************************************************************

GATHERING FACTS ***************************************************************
ok: [localhost]

TASK: [debug msg={{ ansible_alc0.ipv4.address }}] *****************************
fatal: [localhost] =&gt; One or more undefined variables: 'list object' has no attribute 'address'

FATAL: all hosts have already failed -- aborting

PLAY RECAP ********************************************************************
           to retry, use: --limit @/home/gregm/test.retry

localhost                  : ok=1    changed=0    unreachable=1    failed=0"><pre class="notranslate"><code class="notranslate">PLAY [localhost] **************************************************************

GATHERING FACTS ***************************************************************
ok: [localhost]

TASK: [debug msg={{ ansible_alc0.ipv4.address }}] *****************************
fatal: [localhost] =&gt; One or more undefined variables: 'list object' has no attribute 'address'

FATAL: all hosts have already failed -- aborting

PLAY RECAP ********************************************************************
           to retry, use: --limit @/home/gregm/test.retry

localhost                  : ok=1    changed=0    unreachable=1    failed=0
</code></pre></div>