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

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?