Validate Pepa templates

def validate(output, resource):
    '''
    Validate Pepa templates
    '''
    try:
        import cerberus  # pylint: disable=import-error
    except ImportError:
        log.critical('You need module cerberus in order to use validation')
        return

    roots = __opts__['pepa_roots']

    valdir = os.path.join(roots['base'], resource, 'validate')

    all_schemas = {}
    pepa_schemas = []
    for fn in glob.glob(valdir + '/*.yaml'):
        log.info("Loading schema: %s", fn)
        with salt.utils.files.fopen(fn) as fhr:
            template = jinja2.Template(fhr.read())
        data = output
        data['grains'] = __grains__.copy()
        data['pillar'] = __pillar__.copy()
        schema = salt.utils.yaml.safe_load(template.render(data))
        all_schemas.update(schema)
        pepa_schemas.append(fn)

    val = cerberus.Validator()
    if not val.validate(output['pepa_keys'], all_schemas):
        for ekey, error in six.iteritems(val.errors):
            log.warning('Validation failed for key %s: %s', ekey, error)

    output['pepa_schema_keys'] = all_schemas
    output['pepa_schemas'] = pepa_schemas