Beispiel #1
0
def delete_group(module=None, iam=None, name=None):
    changed = False
    try:
        iam.delete_group(name)
    except boto.exception.BotoServerError as err:
        error_msg = boto_exception(err)
        if ('must delete policies first') in error_msg:
            for policy in iam.get_all_group_policies(
                    name).list_group_policies_result.policy_names:
                iam.delete_group_policy(name, policy)
            try:
                iam.delete_group(name)
            except boto.exception.BotoServerError as err:
                error_msg = boto_exception(err)
                if ('must delete policies first') in error_msg:
                    module.fail_json(
                        changed=changed,
                        msg=
                        "All inline policies have been removed. Though it appears"
                        "that %s has Managed Polices. This is not "
                        "currently supported by boto. Please detach the policies "
                        "through the console and try again." % name)
                else:
                    module.fail_json(changed=changed, msg=str(error_msg))
            else:
                changed = True
        else:
            module.fail_json(changed=changed, msg=str(error_msg))
    else:
        changed = True
    return changed, name
Beispiel #2
0
def delete_group(module=None, iam=None, name=None):
    changed = False
    try:
        iam.delete_group(name)
    except boto.exception.BotoServerError as err:
        error_msg = boto_exception(err)
        if ('must detach all policies first') in error_msg:
            for policy in iam.get_all_group_policies(name).list_group_policies_result.policy_names:
                iam.delete_group_policy(name, policy)
            try:
                iam.delete_group(name)
            except boto.exception.BotoServerError as  err:
                error_msg = boto_exception(err)
                if ('must detach all policies first') in error_msg:
                      module.fail_json(changed=changed, msg="All inline polices have been removed. Though it appears"
                                                            "that %s has Managed Polices. This is not "
                                                            "currently supported by boto. Please detach the polices "
                                                            "through the console and try again." % name)
                else:
                    module.fail_json(changed=changed, msg=str(err))
            else:
                changed = True
    else:
        changed = True
    return changed, name
def delete_users():
    with open(DATA_FILE_NAME, 'rU') as data_file:
        user_reader = csv.reader(data_file)
        for row in user_reader:
            user = row[0]
            try:
                iam.delete_login_profile(user)
                iam.remove_user_from_group(group, user)
                iam.delete_user(user)
                print("Deleted " + user)
            except boto.exception.BotoServerError as e:
                print "Problems deleting %s.  Exiting due to error: %s" % (user, str(e.message))
                exit(1)
    
    iam.delete_group_policy(group, policy_name)
    iam.delete_group(group)
def delete_users():
    with open(DATA_FILE_NAME, 'rU') as data_file:
        user_reader = csv.reader(data_file)
        for row in user_reader:
            user = row[0]
            try:
                iam.delete_login_profile(user)
                iam.remove_user_from_group(group, user)
                iam.delete_user(user)
                print("Deleted " + user)
            except boto.exception.BotoServerError as e:
                print "Problems deleting %s.  Exiting due to error: %s" % (
                    user, str(e.message))
                exit(1)

    iam.delete_group_policy(group, policy_name)
    iam.delete_group(group)
Beispiel #5
0
def delete_group(iam, name):
    iam.delete_group(name)
    changed = True
    return changed, name