From 275b3972cb147583bdd7cd394df708f9d97d7f84 Mon Sep 17 00:00:00 2001 From: Prasad Katti Date: Wed, 16 Oct 2019 10:01:51 -0700 Subject: [PATCH] [lightsail] make delete operation idempotent (#63317) Fixes #63315 --- lib/ansible/modules/cloud/amazon/lightsail.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/ansible/modules/cloud/amazon/lightsail.py b/lib/ansible/modules/cloud/amazon/lightsail.py index 202d62458e7..4766c56ee17 100644 --- a/lib/ansible/modules/cloud/amazon/lightsail.py +++ b/lib/ansible/modules/cloud/amazon/lightsail.py @@ -249,6 +249,10 @@ def delete_instance(module, client, instance_name): if e.response['Error']['Code'] != 'NotFoundException': module.fail_json(msg='Error finding instance {0}, error: {1}'.format(instance_name, e)) + # If instance doesn't exist, then return with 'changed:false' + if not inst: + return changed, {} + # Wait for instance to exit transition state before deleting if wait: while wait_max > time.time() and inst is not None and inst['state']['name'] in ('pending', 'stopping'):