def main(role, ou, assume, profile, output, regions, active):
    """Generate a c7n-org accounts config file using AWS Organizations

    With c7n-org you can then run policies or arbitrary scripts across
    accounts.
    """

    session = get_session(assume, 'c7n-org', profile)
    client = session.client('organizations')
    accounts = []
    for path in ou:
        ou = get_ou_from_path(client, path)
        accounts.extend(get_accounts_for_ou(client, ou, active))

    results = []
    for a in accounts:
        tags = []
        path_parts = a['Path'].strip('/').split('/')
        for idx, _ in enumerate(path_parts):
            tags.append("path:/%s" % "/".join(path_parts[:idx + 1]))

        ainfo = {
            'account_id': a['Id'],
            'email': a['Email'],
            'name': a['Name'],
            'tags': tags,
            'role': role.format(**a)}
        if regions:
            ainfo['regions'] = regions
        results.append(ainfo)

    print(
        yaml.safe_dump(
            {'accounts': results},
            default_flow_style=False),
        file=output)
Generate a c7n-org accounts config file using AWS Organizations

    With c7n-org you can then run policies or arbitrary scripts across
    accounts.