Issue 1:
From @weaseal on 2016-12-02T01:49:18Z

ISSUE TYPE

Bug Report

COMPONENT NAME

component: ec2_ami

ANSIBLE VERSION

$ ansible --version
/usr/lib64/python2.6/site-packages/cryptography/__init__.py:26: DeprecationWarning: Python 2.6 is no longer supported by the Python core team, please upgrade your Python. A future version of cryptography will drop support for Python 2.6
DeprecationWarning
ansible 2.2.0.0
config file = /etc/ansible/ansible.cfg
configured module search path = Default w/o overrides

CONFIGURATION

n/a

OS / ENVIRONMENT

$ cat /etc/redhat-release

Red Hat Enterprise Linux Server release 6.7 (Santiago)

$ sudo pip list | grep -i boto

DEPRECATION: Python 2.6 is no longer supported by the Python core team, please upgrade your Python. A future version of pip will drop support for Python 2.6

boto (2.43.0)

boto3 (1.4.2)

botocore (1.4.81)

SUMMARY

ec2_ami module crashes and fails to save AMI

STEPS TO REPRODUCE

Set up an instance and try to save it using ec2_ami module

- name: Save the app server as an AMI
ec2_ami:
description: "App server - created {{ ansible_date_time.iso8601 }}"
instance_id: "{{ item.id }}"
name: "Appserver.{{ ansible_date_time.date }}.{{ ansible_date_time.hour }}.{{ ansible_date_time.minute }}.{{ ansible_date_time.second }} {{ ansible_date_time.tz_offset }} {{ scm_branch.stdout }}"
region: "{{ item.region }}"
wait: yes
launch_permissions:
user_ids: ["{{ aws_account_number_prod }}"]
tags:
git_branch: "{{ scm_branch.stdout }}"
with_items: "{{ ec2.instances }}"
register: saved_ami

EXPECTED RESULTS

For it to not crash.

ACTUAL RESULTS

TASK [save_ami : Save the app server as an AMI] ******************
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: AttributeError: 'Image' object has no attribute 'creationDate'
failed: [127.0.0.1] (item={u'kernel': None, u'root_device_type': u'ebs', u'private_dns_name': u'ip-10-10-0-140.eu-central-1.compute.internal', u'public_ip': u'xx.xx.xx.xx', u'private_ip': u'10.10.0.140', u'id': u'i-718cb3cd', u'ebs_optimized': False, u'state': u'running', u'virtualization_type': u'hvm', u'architecture': u'x86_64', u'ramdisk': None, u'block_device_mapping': {u'/dev/sdb': {u'status': u'attached', u'delete_on_termination': False, u'volume_id': u'vol-xxxxxxxx'}, u'/dev/sda1': {u'status': u'attached', u'delete_on_termination': True, u'volume_id': u'vol-xxxxxxxx'}, u'/dev/sdc': {u'status': u'attached', u'delete_on_termination': True, u'volume_id': u'vol-xxxxxxxx'}}, u'key_name': u'xxxxxxxx', u'image_id': u'ami-xxxxxxxx', u'tenancy': u'default', u'groups': {u'sg-xxxxxxx': u'image_build'}, u'public_dns_name': u'', u'state_code': 16, u'tags': {u'Name': u'image_build xxxxxxxx'}, u'placement': u'eu-central-1b', u'ami_launch_index': u'0', u'dns_name': u'', u'region': u'eu-central-1', u'launch_time': u'2016-12-02T01:03:35.000Z', u'instance_type': u't2.small', u'root_device_name': u'/dev/sda1', u'hypervisor': u'xen'}) => {"failed": true, "item": {"ami_launch_index": "0", "architecture": "x86_64", "block_device_mapping": {"/dev/sda1": {"delete_on_termination": true, "status": "attached", "volume_id": "vol-xxxxxxxx"}, "/dev/sdb": {"delete_on_termination": false, "status": "attached", "volume_id": "vol-xxxxxxxx"}, "/dev/sdc": {"delete_on_termination": true, "status": "attached", "volume_id": "vol-xxxxxxxx"}}, "dns_name": "", "ebs_optimized": false, "groups": {"sg-xxxxxxxx": "image_build"}, "hypervisor": "xen", "id": "i-718cb3cd", "image_id": "ami-xxxxxxxx", "instance_type": "t2.small", "kernel": null, "key_name": "xxxxxxxx", "launch_time": "2016-12-02T01:03:35.000Z", "placement": "eu-central-1b", "private_dns_name": "ip-10-10-0-140.eu-central-1.compute.internal", "private_ip": "10.10.0.140", "public_dns_name": "", "public_ip": "xx.xx.xx.xx", "ramdisk": null, "region": "eu-central-1", "root_device_name": "/dev/sda1", "root_device_type": "ebs", "state": "running", "state_code": 16, "tags": {"Name": "image_build"}, "tenancy": "default", "virtualization_type": "hvm"}, "module_stderr": "Traceback (most recent call last):\n File \"/tmp/ansible_ault7w/ansible_module_ec2_ami.py\", line 560, in <module>\n main()\n File \"/tmp/ansible_ault7w/ansible_module_ec2_ami.py\", line 552, in main\n create_image(module, ec2)\n File \"/tmp/ansible_ault7w/ansible_module_ec2_ami.py\", line 419, in create_image\n module.exit_json(msg=\"AMI creation operation complete\", changed=True, **get_ami_info(img))\n File \"/tmp/ansible_ault7w/ansible_module_ec2_ami.py\", line 332, in get_ami_info\n creationDate=image.creationDate,\nAttributeError: 'Image' object has no attribute 'creationDate'\n", "module_stdout": "", "msg": "MODULE FAILURE"}

Copied from original issue: ansible/ansible-modules-core#5790

Issue 2:
ISSUE TYPE

Bug Report

COMPONENT NAME

ec2_ami module

ANSIBLE VERSION

ansible 2.3.0.0
config file = /home/user/deployment/ansible/ansible.cfg
configured module search path = Default w/o overrides
python version = 3.4.2 (default, Oct 8 2014, 10:45:20) [GCC 4.9.1]
Also 2.2 fails on same error
boto 2.46.1

CONFIGURATION

[defaults]

inventory=hosts

roles_path=roles

host_key_checking=False

timeout=60

[privilege_escalation]

become_method=sudo

OS / ENVIRONMENT

Debian Jessie x86_64

SUMMARY

ec2_ami module creates an AMI, but fails with AttributeError: 'Image' object has no attribute 'creationDate'

STEPS TO REPRODUCE

Create a role or tasks which uses ec2_ami to create an AMI from instance

# Generate AMI from one of it (are equal) to use in ASG
- name: Create AMI
ec2_ami:
aws_access_key: "{{ ec2_access_key }}"
aws_secret_key: "{{ ec2_secret_key }}"
region: "{{ ec2_region }}"
instance_id: "{{ ec2_remote_facts.instances.0.id }}"
wait: yes
description: Backend provisioned {{ ansible_date_time.iso8601 }}
name: backend-{{ ansible_date_time.epoch }}
tags:
Name: Backend {{ ansible_date_time.iso8601 }}
Environment: Production
register: image

EXPECTED RESULTS

The AMI is created and its data is returned in variable "image"

ACTUAL RESULTS

The AMI is created successfully, but data is not recovered and in fact task fails with

fatal: [172.31.51.42]: FAILED! => {"changed": false, "failed": true, "module_stderr": "Traceback (most recent call last):\n File \"/tmp/ansible_Cdn7m2/ansible_module_ec2_ami.py\", line 640, in <module>\n main()\n File \"/tmp/ansible_Cdn7m2/ansible_module_ec2_ami.py\", line 632, in main\n create_image(module, ec2)\n File \"/tmp/ansible_Cdn7m2/ansible_module_ec2_ami.py\", line 496, in create_image\n module.exit_json(msg=\"AMI creation operation complete\", changed=True, **get_ami_info(img))\n File \"/tmp/ansible_Cdn7m2/ansible_module_ec2_ami.py\", line 389, in get_ami_info\n creationDate=image.creationDate,\nAttributeError: 'Image' object has no attribute 'creationDate'\n", "module_stdout": "", "msg": "MODULE FAILURE", "rc": 0}