attempt to fix check mode when state='absent'

This commit is contained in:
Brian Coca 2015-07-16 11:36:40 -04:00
parent 2790af2858
commit a9e8cae82e

View file

@ -127,25 +127,23 @@ def main():
if state == 'absent': if state == 'absent':
if key: if key:
'''found a match, delete it''' '''found a match, delete it'''
try: if not module.check_mode:
key.delete() try:
if wait: key.delete()
start = time.time() if wait:
action_complete = False start = time.time()
while (time.time() - start) < wait_timeout: action_complete = False
if not ec2.get_key_pair(name): while (time.time() - start) < wait_timeout:
action_complete = True if not ec2.get_key_pair(name):
break action_complete = True
time.sleep(1) break
if not action_complete: time.sleep(1)
module.fail_json(msg="timed out while waiting for the key to be removed") if not action_complete:
except Exception, e: module.fail_json(msg="timed out while waiting for the key to be removed")
module.fail_json(msg="Unable to delete key pair '%s' - %s" % (key, e)) except Exception, e:
else: module.fail_json(msg="Unable to delete key pair '%s' - %s" % (key, e))
key = None key = None
changed = True changed = True
else:
'''no match found, no changes required'''
# Ensure requested key is present # Ensure requested key is present
elif state == 'present': elif state == 'present':