Fix an issue where by a call to ec2.get_image wasn't wrapped in a try/except, and would occasionally throw an exception in the wild. Also greatly simplifies two of the ugliest known loops to man down into a single loop. (#2554)
module.fail_json(msg="Error while trying to find the new image. Using wait=yes and/or a longer wait_timeout may help. %s: %s"%(e.error_code,e.error_message))
else:
finally:
module.fail_json(msg="Error while trying to find the new image. Using wait=yes and/or a longer wait_timeout may help.")
time.sleep(1)
else:
module.fail_json(msg="timed out waiting for image to be recognized")
# wait here until the image is created
ifimg.state!='available':
wait_timeout=time.time()+wait_timeout
module.fail_json(msg="Error while trying to find the new image. Using wait=yes and/or a longer wait_timeout may help.")