Issue 1:
*** THIS IS A DUPLICATE BUG REPORT ***

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.

*** ORIGINAL REPORT ***

#14593

*** ACTUAL REPORT ***

Issue Type:

Bug Report

COMPONENT NAME

ec2 module

ANSIBLE VERSION

ansible 2.1.0 (devel 6a62ad6) last updated 2016/02/01 13:04:11 (GMT -700)

lib/ansible/modules/core: (detached HEAD 93d0218) last updated 2016/02/01 13:04:24 (GMT -700)

lib/ansible/modules/extras: (detached HEAD fff5ae6) last updated 2016/02/01 13:04:31 (GMT -700)

config file = /etc/ansible/ansible.cfg

configured module search path = Default w/o overrides

CONFIGURATION

no significant changes,

scp_if_ssh=True

ENVIRONMENT

N/A

SUMMARY

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.

Additionally, the nesting of these variables is different than what is described in the documentation on http://docs.ansible.com/ansible/ec2_vol_module.html, which states that you should be able to access the instances simply by ec2.instances. Did this change with 2.0?

Steps To Reproduce:

Here is my list I am iterating over:

server_environments:

environment: production

servers:

{ type: bastion, name: j-bastion, private_ip: 10.1.1.250 }

{ type: app, name: j-delete, private_ip: 10.1.1.106 }

Here is my playbook:

hosts: localhost

gather_facts: False

roles:

provision_ec2

Here is my provision_ec2 role:

name: Launch instances based on server list

ec2:

key_name: ansible_provisioning.txt

group_id: 'sg-81398ee4', 'sg-a6398ec3'

instance_type: t2.medium

image: ami-06116566

termination_protection: yes

wait: true

region: us-west-2

instance_tags:

Type: "{{ item.0.environment }}"

Name: "{{ item.1.name }}"

exact_count: 1

count_tag:

Name: "{{ item.1.name }}"

vpc_subnet_id: subnet-819f7gd2

assign_public_ip: yes

private_ip: "{{ item.1.private_ip }}"

register: ec2

with_subelements:

server_environments

servers

Use this to see what is contained in the ec2 variable

name: debug...

debug: var=ec2.results

This DID NOT work (shown as acceptable int the documentation)

name: Attach volumes to created instances

ec2_vol:

instance: "{{ item.id }}"

device_name: /dev/xvdb

volume_size: 200

volume_type: gp2

iops: 600

with_items: ec2.instances

register: ec2_vol

This DID work but is not reliable

name: Attach volumes to created instances

ec2_vol:

instance: "{{ item.tagged_instances.0.id }}"

device_name: /dev/xvdb

volume_size: 200

volume_type: gp2

iops: 600

with_items: ec2.results

register: ec2_vol

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

Expected/Actual Results:

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.

Please close this one, and reopen that one.

Issue 2:
Issue Type: Bug Report

Ansible Version:

ansible 1.6.6 linux (centos 6.5)

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)

Environment:

ansible is run local to the server in each instances

host: Centos 6.5 and OpenBSD 5.5

Summary:

An OpenBSD system not able to assign retrieved fact for ansible_interface.ipv4.address to variable.

Steps To Reproduce:

create play (Centos 6.5)

---
# 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

create paly (OpenBSD 5.5)

---
# 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 }}

Expected Results:

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.

for reference, I include collected facts from the Centos 6.5 host:

"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"

Centos 6.5 results:

PLAY [localhost] **************************************************************

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

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

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

PLAY RECAP ********************************************************************
localhost : ok=3 changed=0 unreachable=0 failed=0

Actual Results:

For referance, I included fact collected from the OpenBSD 5.5 host

localhost | success >> {
"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"
}
],

OpenBSD 5.5 results

PLAY [localhost] **************************************************************

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

TASK: [debug msg={{ ansible_alc0.ipv4.address }}] *****************************
fatal: [localhost] => 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