fixed the delete user function
now works with or without loginprofile (password)
This commit is contained in:
parent
76cd8381f8
commit
3d8f0b5d95
1 changed files with 11 additions and 5 deletions
|
@ -198,10 +198,16 @@ def delete_user(module, iam, name):
|
||||||
iam.get_all_access_keys(name).list_access_keys_result.access_key_metadata]
|
iam.get_all_access_keys(name).list_access_keys_result.access_key_metadata]
|
||||||
for key in current_keys:
|
for key in current_keys:
|
||||||
iam.delete_access_key(key, name)
|
iam.delete_access_key(key, name)
|
||||||
login_profile = iam.get_login_profiles(name)
|
try:
|
||||||
if login_profile:
|
login_profile = iam.get_login_profiles(name).get_login_profile_response
|
||||||
iam.delete_login_profile(name)
|
except boto.exception.BotoServerError, err:
|
||||||
del_meta = iam.delete_user(name).delete_user_response
|
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:
|
except Exception as ex:
|
||||||
module.fail_json(changed=False, msg="delete failed %s" %ex)
|
module.fail_json(changed=False, msg="delete failed %s" %ex)
|
||||||
if ('must detach all policies first') in error_msg:
|
if ('must detach all policies first') in error_msg:
|
||||||
|
@ -661,7 +667,7 @@ def main():
|
||||||
try:
|
try:
|
||||||
set_users_groups(module, iam, name, '')
|
set_users_groups(module, iam, name, '')
|
||||||
del_meta, name, changed = delete_user(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:
|
except Exception as ex:
|
||||||
module.fail_json(changed=changed, msg=str(ex))
|
module.fail_json(changed=changed, msg=str(ex))
|
||||||
|
|
Loading…
Reference in a new issue