Squash of 3 commits for bugfix.
Absent unction was not working on user with login profile also fixed the exception handling fixed the delete user function now works with or without loginprofile (password) typo
This commit is contained in:
parent
4c08545974
commit
8eb04fe0d3
1 changed files with 12 additions and 6 deletions
|
@ -207,10 +207,16 @@ def delete_user(module, iam, name):
|
|||
iam.get_all_access_keys(name).list_access_keys_result.access_key_metadata]
|
||||
for key in current_keys:
|
||||
iam.delete_access_key(key, name)
|
||||
login_profile = iam.get_login_profiles(name)
|
||||
if login_profile:
|
||||
iam.delete_login_profile(name)
|
||||
del_meta = iam.delete_user(name).delete_user_response
|
||||
try:
|
||||
login_profile = iam.get_login_profiles(name).get_login_profile_response
|
||||
except boto.exception.BotoServerError, err:
|
||||
error_msg = boto_exception(err)
|
||||
if ('Cannot find Login Profile') in error_msg:
|
||||
|
||||
del_meta = iam.delete_user(name).delete_user_response
|
||||
else:
|
||||
iam.delete_login_profile(name)
|
||||
del_meta = iam.delete_user(name).delete_user_response
|
||||
except Exception as ex:
|
||||
module.fail_json(changed=False, msg="delete failed %s" %ex)
|
||||
if ('must detach all policies first') in error_msg:
|
||||
|
@ -226,7 +232,7 @@ def delete_user(module, iam, name):
|
|||
"currently supported by boto. Please detach the polices "
|
||||
"through the console and try again." % name)
|
||||
else:
|
||||
module.fail_json(changed=changed, msg=str(del_meta))
|
||||
module.fail_json(changed=changed, msg=str(error_msg))
|
||||
else:
|
||||
changed = True
|
||||
return del_meta, name, changed
|
||||
|
@ -673,7 +679,7 @@ def main():
|
|||
try:
|
||||
set_users_groups(module, iam, name, '')
|
||||
del_meta, name, changed = delete_user(module, iam, name)
|
||||
module.exit_json(deleted_user=name, changed=changed, orig_user_list=orig_user_list)
|
||||
module.exit_json(deleted_user=name, changed=changed)
|
||||
|
||||
except Exception as ex:
|
||||
module.fail_json(changed=changed, msg=str(ex))
|
||||
|
|
Loading…
Reference in a new issue