<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:

def targets(tgt, tgt_type='glob', **kwargs):
    '''
    Return the targets from the directory of flat yaml files,
    checks opts for location.
    '''
    roster_dir = __opts__.get('roster_dir', '/etc/salt/roster.d')
    # Match the targets before rendering to avoid opening files unnecessarily.
    raw = dict.fromkeys(os.listdir(roster_dir), '')
    log.debug('Filtering %d minions in %s', len(raw), roster_dir)
    matched_raw = __utils__['roster_matcher.targets'](raw, tgt, tgt_type, 'ipv4')
    rendered = {minion_id: _render(os.path.join(roster_dir, minion_id), **kwargs)
                for minion_id in matched_raw}
    pruned_rendered = {id_: data for id_, data in rendered.items() if data}
    log.debug('Matched %d minions with tgt=%s and tgt_type=%s.'
              ' Discarded %d matching filenames because they had rendering errors.',
              len(rendered), tgt, tgt_type, len(rendered) - len(pruned_rendered))
    return pruned_rendered