def _get_hosts_list(dynamic_inventory, top_level_group='all'):
    """Get a list of hosts.

    Args:
        dynamic_inventory (dict): Dynamic inventory dictionary
        top_level_group (str): Name of top level group

    Returns:
        list: List containing all inventory hosts
    """
    hosts_list = []
    if 'hosts' in dynamic_inventory[top_level_group]:
        hosts_list += dynamic_inventory[top_level_group]['hosts']
    if 'children' in dynamic_inventory[top_level_group]:
        for child in dynamic_inventory[top_level_group]['children']:
            hosts_list += _get_hosts_list(dynamic_inventory, child)
    return hosts_list