Merge pull request #1740 from bcoca/ec2_key_check_fix

attempt to fix check mode when state='absent'
reviewable/pr18780/r1
Brian Coca 9 years ago
commit 5fcc0be25b

@ -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':

Loading…
Cancel
Save