# InvalidAMIID.Unavailable: The image ID 'ami-XXXXXXX' is no longer available

**URL:** <https://forum.ansible.com/t/invalidamiid-unavailable-the-image-id-ami-xxxxxxx-is-no-longer-available/24572>\
**Category:** Ansible Project\
**Created:** [May 24, 2017, 9:34pm UTC](https://forum.ansible.com/t/invalidamiid-unavailable-the-image-id-ami-xxxxxxx-is-no-longer-available/24572 "2017-05-24T21:34:47Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Radhika\_Karthik](https://avatars.discourse-cdn.com/v4/letter/r/46a35a/32.png) [@Radhika\_Karthik](https://forum.ansible.com/u/Radhika_Karthik)\
**Post date:** [May 24, 2017, 9:34pm UTC](https://forum.ansible.com/t/invalidamiid-unavailable-the-image-id-ami-xxxxxxx-is-no-longer-available/24572/1 "2017-05-24T21:34:47Z")

</div>

The following lines of code is not working in Ansible version 2.3. Same code works fine in ansible version 2.0.0

If dm\_ami-AMI ID already exists, ansible throws below error  
“msg”: “Image ami-957313f5 does not exist”

If dm\_ami-AMI ID doesn’t exist, ansible throws below error  
“msg”: "The conditional check ‘dm\_ami.results[0].ami\_id is defined’ failed.

name: Find the AMI details  
ec2\_ami\_find:  
name: ‘{{ dm\_ami\_name }}’  
region: ‘{{ aws\_region }}’  
no\_result\_action: success  
register: dm\_ami  
ignore\_errors: True

debug: msg="DataMoverAMI = {{ dm\_ami }}

name: Remove Previous AMI if exists.

ec2\_ami:

region: ‘{{ aws\_region }}’

image\_id: ‘{{ dm\_ami.results[0].ami\_id }}’

state: absent

delete\_snapshot: yes

when: dm\_ami.results[0].ami\_id is defined

name: Create AMI from instance id.

ec2\_ami:

instance\_id: ‘{{ dm\_instance\_id }}’

name: ‘{{ dm\_ami\_name }}’

description: ‘{{ def\_ami\_description }}’

region: ‘{{ aws\_region }}’

wait: yes

Have anyone noticed this issue? Do we have a workaround other than go back to the previous ansible version?
