<p dir="auto">From <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/weaseal/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/weaseal">@weaseal</a> on 2016-12-02T01:49:18Z</p>

<h5 dir="auto">ISSUE TYPE</h5>

<ul dir="auto">
<li>Bug Report</li>
</ul>
<h5 dir="auto">COMPONENT NAME</h5>

<p dir="auto">component: ec2_ami</p>
<h5 dir="auto">ANSIBLE VERSION</h5>

<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="$ 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"><pre class="notranslate"><code class="notranslate">$ 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
</code></pre></div>
<h5 dir="auto">CONFIGURATION</h5>

<p dir="auto">n/a</p>
<h5 dir="auto">OS / ENVIRONMENT</h5>

<p dir="auto">$ cat /etc/redhat-release<br>
Red Hat Enterprise Linux Server release 6.7 (Santiago)<br>
$ sudo pip list | grep -i boto<br>
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<br>
boto (2.43.0)<br>
boto3 (1.4.2)<br>
botocore (1.4.81)</p>
<h5 dir="auto">SUMMARY</h5>
<p dir="auto">ec2_ami module crashes and fails to save AMI</p>
<h5 dir="auto">STEPS TO REPRODUCE</h5>

<p dir="auto">Set up an instance and try to save it using ec2_ami module</p>

<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="- name: Save the app server as an AMI
  ec2_ami:
    description: &quot;App server - created {{ ansible_date_time.iso8601 }}&quot;
    instance_id: &quot;{{ item.id }}&quot;
    name: &quot;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 }}&quot;
    region: &quot;{{ item.region }}&quot;
    wait: yes
    launch_permissions:
      user_ids: [&quot;{{ aws_account_number_prod }}&quot;]
    tags:
      git_branch: &quot;{{ scm_branch.stdout }}&quot;
  with_items: &quot;{{ ec2.instances }}&quot;
  register: saved_ami
"><pre class="notranslate"><code class="notranslate">- 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

</code></pre></div>

<h5 dir="auto">EXPECTED RESULTS</h5>

<p dir="auto">For it to not crash.</p>
<h5 dir="auto">ACTUAL RESULTS</h5>


<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="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'}) =&gt; {&quot;failed&quot;: true, &quot;item&quot;: {&quot;ami_launch_index&quot;: &quot;0&quot;, &quot;architecture&quot;: &quot;x86_64&quot;, &quot;block_device_mapping&quot;: {&quot;/dev/sda1&quot;: {&quot;delete_on_termination&quot;: true, &quot;status&quot;: &quot;attached&quot;, &quot;volume_id&quot;: &quot;vol-xxxxxxxx&quot;}, &quot;/dev/sdb&quot;: {&quot;delete_on_termination&quot;: false, &quot;status&quot;: &quot;attached&quot;, &quot;volume_id&quot;: &quot;vol-xxxxxxxx&quot;}, &quot;/dev/sdc&quot;: {&quot;delete_on_termination&quot;: true, &quot;status&quot;: &quot;attached&quot;, &quot;volume_id&quot;: &quot;vol-xxxxxxxx&quot;}}, &quot;dns_name&quot;: &quot;&quot;, &quot;ebs_optimized&quot;: false, &quot;groups&quot;: {&quot;sg-xxxxxxxx&quot;: &quot;image_build&quot;}, &quot;hypervisor&quot;: &quot;xen&quot;, &quot;id&quot;: &quot;i-718cb3cd&quot;, &quot;image_id&quot;: &quot;ami-xxxxxxxx&quot;, &quot;instance_type&quot;: &quot;t2.small&quot;, &quot;kernel&quot;: null, &quot;key_name&quot;: &quot;xxxxxxxx&quot;, &quot;launch_time&quot;: &quot;2016-12-02T01:03:35.000Z&quot;, &quot;placement&quot;: &quot;eu-central-1b&quot;, &quot;private_dns_name&quot;: &quot;ip-10-10-0-140.eu-central-1.compute.internal&quot;, &quot;private_ip&quot;: &quot;10.10.0.140&quot;, &quot;public_dns_name&quot;: &quot;&quot;, &quot;public_ip&quot;: &quot;xx.xx.xx.xx&quot;, &quot;ramdisk&quot;: null, &quot;region&quot;: &quot;eu-central-1&quot;, &quot;root_device_name&quot;: &quot;/dev/sda1&quot;, &quot;root_device_type&quot;: &quot;ebs&quot;, &quot;state&quot;: &quot;running&quot;, &quot;state_code&quot;: 16, &quot;tags&quot;: {&quot;Name&quot;: &quot;image_build&quot;}, &quot;tenancy&quot;: &quot;default&quot;, &quot;virtualization_type&quot;: &quot;hvm&quot;}, &quot;module_stderr&quot;: &quot;Traceback (most recent call last):\n  File \&quot;/tmp/ansible_ault7w/ansible_module_ec2_ami.py\&quot;, line 560, in &lt;module&gt;\n    main()\n  File \&quot;/tmp/ansible_ault7w/ansible_module_ec2_ami.py\&quot;, line 552, in main\n    create_image(module, ec2)\n  File \&quot;/tmp/ansible_ault7w/ansible_module_ec2_ami.py\&quot;, line 419, in create_image\n    module.exit_json(msg=\&quot;AMI creation operation complete\&quot;, changed=True, **get_ami_info(img))\n  File \&quot;/tmp/ansible_ault7w/ansible_module_ec2_ami.py\&quot;, line 332, in get_ami_info\n    creationDate=image.creationDate,\nAttributeError: 'Image' object has no attribute 'creationDate'\n&quot;, &quot;module_stdout&quot;: &quot;&quot;, &quot;msg&quot;: &quot;MODULE FAILURE&quot;}"><pre class="notranslate"><code class="notranslate">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'}) =&gt; {"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 &lt;module&gt;\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"}
</code></pre></div>
<p dir="auto">Copied from original issue: <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="193012665" data-permission-text="Title is private" data-url="https://github.com/ansible/ansible-modules-core/issues/5790" data-hovercard-type="issue" data-hovercard-url="/ansible/ansible-modules-core/issues/5790/hovercard" href="https://github.com/ansible/ansible-modules-core/issues/5790">ansible/ansible-modules-core#5790</a></p>
<h5 dir="auto">ISSUE TYPE</h5>

<ul dir="auto">
<li>Bug Report</li>
</ul>
<h5 dir="auto">COMPONENT NAME</h5>

<p dir="auto">ec2_ami module</p>
<h5 dir="auto">ANSIBLE VERSION</h5>

<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="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"><pre class="notranslate"><code class="notranslate">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
</code></pre></div>
<h5 dir="auto">CONFIGURATION</h5>

<p dir="auto">[defaults]<br>
inventory=hosts<br>
roles_path=roles<br>
host_key_checking=False<br>
timeout=60<br>
[privilege_escalation]<br>
become_method=sudo</p>
<h5 dir="auto">OS / ENVIRONMENT</h5>

<p dir="auto">Debian Jessie x86_64</p>
<h5 dir="auto">SUMMARY</h5>

<p dir="auto">ec2_ami module creates an AMI, but fails with  AttributeError: 'Image' object has no attribute 'creationDate'</p>
<h5 dir="auto">STEPS TO REPRODUCE</h5>

<p dir="auto">Create a role or tasks which uses ec2_ami to create an AMI from instance</p>

<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="# Generate AMI from one of it (are equal) to use in ASG
- name: Create AMI
  ec2_ami:
    aws_access_key: &quot;{{ ec2_access_key }}&quot;
    aws_secret_key: &quot;{{ ec2_secret_key }}&quot;
    region: &quot;{{ ec2_region }}&quot;
    instance_id: &quot;{{ ec2_remote_facts.instances.0.id }}&quot;
    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"><pre class="notranslate"><code class="notranslate"># 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
</code></pre></div>

<h5 dir="auto">EXPECTED RESULTS</h5>

<p dir="auto">The AMI is created and its data is returned in variable "image"</p>
<h5 dir="auto">ACTUAL RESULTS</h5>

<p dir="auto">The AMI is created successfully, but data is not recovered and in fact task fails with</p>

<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="fatal: [172.31.51.42]: FAILED! =&gt; {&quot;changed&quot;: false, &quot;failed&quot;: true, &quot;module_stderr&quot;: &quot;Traceback (most recent call last):\n  File \&quot;/tmp/ansible_Cdn7m2/ansible_module_ec2_ami.py\&quot;, line 640, in &lt;module&gt;\n    main()\n  File \&quot;/tmp/ansible_Cdn7m2/ansible_module_ec2_ami.py\&quot;, line 632, in main\n    create_image(module, ec2)\n  File \&quot;/tmp/ansible_Cdn7m2/ansible_module_ec2_ami.py\&quot;, line 496, in create_image\n    module.exit_json(msg=\&quot;AMI creation operation complete\&quot;, changed=True, **get_ami_info(img))\n  File \&quot;/tmp/ansible_Cdn7m2/ansible_module_ec2_ami.py\&quot;, line 389, in get_ami_info\n    creationDate=image.creationDate,\nAttributeError: 'Image' object has no attribute 'creationDate'\n&quot;, &quot;module_stdout&quot;: &quot;&quot;, &quot;msg&quot;: &quot;MODULE FAILURE&quot;, &quot;rc&quot;: 0}"><pre class="notranslate"><code class="notranslate">fatal: [172.31.51.42]: FAILED! =&gt; {"changed": false, "failed": true, "module_stderr": "Traceback (most recent call last):\n  File \"/tmp/ansible_Cdn7m2/ansible_module_ec2_ami.py\", line 640, in &lt;module&gt;\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}
</code></pre></div>